Results 1 to 9 of 9

Thread: QwtPlotMarker

  1. #1
    Join Date
    Apr 2010
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QwtPlotMarker

    Dear All,

    I am using QwtPlotMarker to draw vertical lines in my applications and it works great. My current need is to draw horizontal lines but only on a specific width, not on all the width of the plot.
    Is it possible? If yes, how can I do it?
    NB: I am using QWT 5.2

    Any help will be appreciated

    Lynn

  2. #2
    Join Date
    Feb 2014
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QwtPlotMarker

    This worked for me:
    Qt Code:
    1. QwtPlotMarkere* line=new QwtPlotMarker;
    2. //this I just changed from my code to draw a yellow("#ffff00") ellipse, but when drawing a line the QBrush part doesn't have any impact
    3. int lineWidth=100;
    4. QwtSymbol* symbol = new QwtSymbol( QwtSymbol::HLine, QBrush(QColor("#ffff00")), QPen( Qt::black, 1 ), QSize( lineWidth,0 ) ); //yellow
    5. line->setSymbol(*(symbol));
    6. line->attach(myPlot);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2010
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotMarker

    Thanks for your quick reply.
    It works for me but I am now facing another problem. The documentation says "The symbol is drawn at the specified point." but it looks like it is centered on the point specified in the call to the function setValue(). I tried to add half of the size of the line to the X position but it is still not aligned at the required position.

    Qt Code:
    1. QwtPlotMarker* vMarkerH2 = new QwtPlotMarker();
    2. vMarkerH2->setLabel(QwtText(pEventId));
    3. vMarkerH2->setLabelAlignment ( Qt::AlignRight | Qt::AlignBottom );
    4. QwtSymbol* vLine = new QwtSymbol( QwtSymbol::HLine, QBrush(), QPen ( Qt::darkGreen, 0, Qt::SolidLine ), QSize( canvasMap ( QwtPlot::xBottom ).transform (2000),0 ) );
    5. vMarkerH2->setSymbol(*(vLine));
    6.  
    7. vMarkerH2->attach ( this );
    8. vMarkerH2->hide();
    9. vMarkerH2->setValue (1000 + (2000)/2,axisScaleDiv(QwtPlot::yLeft)->upperBound());
    To copy to clipboard, switch view to plain text mode 

    Do you have any hint on this?

  4. #4
    Join Date
    Feb 2014
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QwtPlotMarker

    what is the line width? is it absolute value in pixels or some vale relative to plot axes (how much the plot is zoomed etc). If relative, I'm guessing the fault lies with setValue() because you always put there the same value. Shouldn't you transform it as well?

  5. #5
    Join Date
    Apr 2010
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotMarker

    I am only doing tests for now, that is why the line length and abscissa are hard coded. I am looking at the plot without zoom for the moment.
    For the line width, I transformed the value related to the scale interval into a point related to the interval of the paint device as the QSize seems to need information in paint device coordinates.
    The function setValue of QwtPlotMarker takes values in the scale intervals, at least it is what I infered as it is not documented.
    My test was to draw a line of 2000 (in scale interval) from the point at the abscissa 1000 (in scale interval) to the right. But I think are right this a problem of scale transformation.
    If I use the default lines of QwtPlotMarker, the class does the scale transformation for me when I zoom, but if I use a symbol where I have to specify the width (and the abscissa which as to be moved of half the width) which depend on the scale factor I am in trouble.
    There is may be another solution than using a symbol. In your case you did not need to account for scaling?

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

    Default Re: QwtPlotMarker

    The geometry of a symbol is always in paint device coordinates. If you want to have lines in plot coordinates you could have a look at QwtPlotIntervalCurve with QwtIntervalSymbol::Bars.

    Uwe

  7. #7
    Join Date
    Feb 2014
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QwtPlotMarker

    I'm not sure if you and I have the same definition of "scale interval" in our heads... SetValue() allows you to set the markers position in plot coordinates. So if for example you have a x::bottom time axis starting with 10s and ending with 110s and you wanted to put a marker in the middle of upper and lower bound, you would use setValue(x, y) to put it there, where x=(upper-lower)/2=60, in this case, (y arbitral).

    In case of a line with a relativeLineWidth=10s, I'd say setValue(x2,y), where x2=x-relativeLineWidth/2

    In my case, I drew cirlces only and wanted their size to remain the same regardless of zooming etc and only for their position to change, so I just hard coded the size with QSize(4,4) and used setValue()


    EDITED: Didn't notice the post from Uwe before posting it. Seems what I wrote stands in opposition to what he wrote... Well, either way, what I wrote, worked for me, maybe because I only set the markers up once with their sambols' size and values , which stayed the same no matter what happened to the plot while it was interacting with the user
    Last edited by genau; 27th February 2014 at 13:21.

  8. #8
    Join Date
    Apr 2010
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotMarker

    genau, thanks for your answernad indeed the situation is different, I need to have the symbol change over the time.

    Uwe, it looks like the class QwtPlotIntervalCurve in a version 6 improvement and I am working with version 5.2. At your opinion would it be worth trying to use a QwtPlotMarker and write an overloading class?

  9. #9
    Join Date
    Apr 2010
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QwtPlotMarker

    For those who may be interested, I finally ended up subclassing QwtPlotMarker.
    As what I needed was to draw 2 vertical lines and a horizontal in between, my class has a extra function setXValues to provide the X positions of the 2 vertical lines and it overloads only the rtti and draw function. In the draw function I only take care of drawing the lines and call the parent class for the label and the symbol (the style being set to NoLine, QwtPlotMarker will not draw any lines).

    Qt Code:
    1. void LinePlotMarker::draw(QPainter *pPainter,const QwtScaleMap &pXMap, const QwtScaleMap &pYMap, const QRect &pBoundingRectangle) const
    2. {
    3. // Draw the vertical and horizontal lines and call the parent implementation for the other parts.
    4. const int vFirstAbscissa = pXMap.transform(mAbscissaFirstLine);
    5. const int vSecondAbscissa = pXMap.transform(mAbscissaSecondLine);
    6. const int vOrdinate = pYMap.transform(yValue());
    7.  
    8. // Draw lines
    9. pPainter->setPen(linePen());
    10.  
    11. //2 vertical lines on the full height of the pBoundingRectangle
    12. QwtPainter::drawLine(pPainter, vFirstAbscissa, pBoundingRectangle.top(), vFirstAbscissa, pBoundingRectangle.bottom());
    13. QwtPainter::drawLine(pPainter, vSecondAbscissa, pBoundingRectangle.top(), vSecondAbscissa, pBoundingRectangle.bottom());
    14.  
    15. // One horizontal line between the 2 vertical lines.
    16. QwtPainter::drawLine(pPainter, vFirstAbscissa, vOrdinate, vSecondAbscissa, vOrdinate);
    17.  
    18. // Call the parent implementation for the other part of the QwtPlotMarker
    19. QwtPlotMarker::draw(pPainter,pXMap,pYMap,pBoundingRectangle);
    20. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QwtPlotMarker and scaling
    By carhun in forum Qwt
    Replies: 14
    Last Post: 10th July 2012, 13:30
  2. QwtPlotMarker example
    By banita in forum Qwt
    Replies: 1
    Last Post: 24th May 2012, 13:19
  3. QwtPlotMarker QwtPlotPicker
    By bss in forum Qwt
    Replies: 1
    Last Post: 15th June 2011, 12:55
  4. Replies: 5
    Last Post: 11th January 2011, 06:37
  5. QwtPlotMarker confusion
    By baray98 in forum Qwt
    Replies: 3
    Last Post: 20th July 2008, 09:47

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
  •  
Qt is a trademark of The Qt Company.