Results 1 to 3 of 3

Thread: Alignment of QwtSymbol

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Alignment of QwtSymbol

    Good morning,

    I have a very short question with a long explanation. So, here's the question:

    So, here is my question: is it possible to change the alignment of a QwtSymbol used in a QwtPlotMarker? if not, is it possible to create a custom symbol (e.g. a polygon)?


    I'm using a QwtPlotMarker with a symbol (DTriangle) to point on a curve:

    Qt Code:
    1. QwtPlotMarker* marker = new QwtPlotMarker();
    2. marker->setAxis(QwtPlot::xTop, QwtPlot::yRight);
    3. marker->setSymbol(QwtSymbol(QwtSymbol::DTriangle, QBrush(m_curve->pen().color().lighter()), QPen(m_curve->pen().color()), QSize(9,11)));
    4. marker->setLabelAlignment(Qt::AlignTop);
    5. marker->attach(plot);
    To copy to clipboard, switch view to plain text mode 

    I get the x/y-coordinates of the point I want to point on. But, if I set marker->setValue(x,y), the triangle is painted with x/y at it's center. I'd like to have it top-aligned, so that the lower corner is at (x,y). My first thought was: shift y by transformed size of the symbol:

    Qt Code:
    1. double symbolHeight = abs(plot->invTransform(QwtPlot::yRight, marker->symbol().size().height()/2) - plot->invTransform(QwtPlot::yRight, 0) );
    2. marker->setValue(x, y+symbolHeight);
    To copy to clipboard, switch view to plain text mode 

    that works - until I zoom in or out. Then, the triangle is too high or too low. This is also clear: the fixed pixel size of the symbol was translated into yValues. When I zoom, the ratio pixel/values changes and so does the distance between marker pos and curve. I know, I could recalculate the marker's position each time I zoom, but maybe there's a better solution...


    thanks!
    Felix

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Alignment of QwtSymbol

    Overload QwtSymbol ( QwtSymbol::drawSymbols in Qwt 6, QwtSymbol::draw in Qwt 5 ) do your translation and call the baseclass.

    Uwe

  3. The following 2 users say thank you to Uwe for this useful post:

    FelixB (11th January 2011), sonulohani (29th May 2012)

  4. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Alignment of QwtSymbol

    that's a good idea, thank you!

Similar Threads

  1. Replies: 4
    Last Post: 29th March 2011, 20:33
  2. QToolbar Alignment
    By ShapeShiftme in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2011, 04:01
  3. QwtSymbol highlighting?
    By shud in forum Qwt
    Replies: 1
    Last Post: 2nd October 2009, 21:42
  4. Help with alignment
    By IsleWitch in forum Newbie
    Replies: 1
    Last Post: 20th October 2007, 18:20
  5. Alignment on QTextTableCell
    By tranfuga25s in forum Qt Programming
    Replies: 0
    Last Post: 24th July 2007, 15:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.