Results 1 to 8 of 8

Thread: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

  1. #1
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Hi, I am using Qwt but having difficulty implementing some features for my plot and would appreciate some advice/tips.

    The first is that I would like to vertically offset Qwt Plot Markers that occur on the same coordinates. As it currently stands any markers that share the same value are painted on top of each other, so if you have a yellow and red diamond on the same coordinates only one of them will appear in the plot. I would like to raise one of the markers vertically so it will reveal the other marker beneath it. I tried to simply increase the y value of the second marker, however that is not a suitable solution especially when you zoom in. Is there a method of partially raising a marker, so that it can reveal a marker beneath it?

    Secondly, I have a set of symbols to denote different phases on the plot. I would like to include them in the legend even when they are absent from the graph. However, to do this currently I am creating QwtPlotMarker objects that are created solely for the purpose of setting their itemattribute legend to true. Is there a better method to add symbols to a QwtLegend than creating dummy plot markers?

    Thanks for your time.

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

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Quote Originally Posted by Krippy View Post
    Is there a method of partially raising a marker, so that it can reveal a marker beneath it?
    If you want to modify the position of the marker text in widget coordinates:
    Qt Code:
    1. class YourMarker: public QwtPlotMarker
    2. {
    3. virtual void drawLabel( QPainter *painter,
    4. const QRectF &canvasRect, const QPointF &pos ) const
    5. {
    6. const QPointF &translatedPos = ...;
    7. QwtPlotMarker::drawLabel( painter, canvasRect, translatedPos );
    8. };
    To copy to clipboard, switch view to plain text mode 
    Secondly, I have a set of symbols to denote different phases on the plot. I would like to include them in the legend even when they are absent from the graph.
    legend and plot are synchronized by QwtPlot::legendDataChanged() and QwtAbstractLegend::updateLegend(). The second is virtual and would be a candidate for appending extra entries.

    But there is also nothing wrong with inserting a dummy item. But if you don't want to insert real markers you can create a dummy QwtPlotItem, where you set the QwtPlotItem::Legend flag and overload QwtPlotItem::legendData(). Note that an item can have more than one entry ( f.e QwtPlotMultiBarChart ).

    Uwe

  3. #3
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Hi Uwe,

    Thanks for the reply. The solution you have provided is definitely what I want to achieve, except rather than the move the text label I want to move the QwtSymbol for the plot marker. I am using Qwt 6.1.3 which means I can use QwtPlotMarker::drawLines() or QwtPlotMarker::drawLabel() to move those elements. However, I cannot see a similar drawSymbol() function. Is there one? If not, how could I best implement one?

    If using dummy markers for the legend is fine, then I will continue to use them as such. Thanks for your help!

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

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Quote Originally Posted by Krippy View Post
    However, I cannot see a similar drawSymbol() function. Is there one? If not, how could I best implement one?
    This one is missing ( should be added to Qwt 6.2 ), but you can overload QwtPlotMarker::draw().
    Simply copy the implementation from qwt_plot_marker.cpp ( 21 lines using public or protected APIs only ) and modify it.

    Uwe

  5. #5
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Excellent, works perfectly. Thanks Uwe.

  6. #6

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Quote Originally Posted by Uwe View Post
    This one is missing ( should be added to Qwt 6.2 ), but you can overload QwtPlotMarker::draw().
    Simply copy the implementation from qwt_plot_marker.cpp ( 21 lines using public or protected APIs only ) and modify it.

    Uwe
    In QT5, I used to be able to draw a symbol with offset by subclassing QwtSymbol, and
    calling in reimplemented drawSymbols like this:

    Qt Code:
    1. virtual void drawSymbols( QPainter *painter, const QPointF *point, int numPoints ) const
    2. {
    3. double symbolWidth = this->size().width();
    4. painter->translate(symbolWidth*0.5,0.0);
    5. QwtSymbol::drawSymbols(painter,point,numPoints);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But it does not seem to do anything in QT6
    Is that approach no longer possible in QT6?
    Thanks

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

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Assuming you are talking about Qwt 5.2/6.1: a method QwtSymbol::drawSymbols doesn't exist in Qwt 5.2.
    In Qwt 6.1 there is one, that falls back to QwtSymbol::renderSymbols, that is virtual.

    Of course there is also QwtPlotCurve::drawSymbols.

    Uwe

  8. #8

    Default Re: Offsetting Qwt Plot Markers and adding symbols to Qwt Legend

    Thanks for quick reply. The code below works

    Qt Code:
    1. class TrianglePen: public QwtSymbol
    2. {
    3. public:
    4. TrianglePen(QColor symbolColor, QSize symbolSize) : QwtSymbol(QwtSymbol::LTriangle, symbolColor, Qt::NoPen,symbolSize)
    5. {
    6. }
    7.  
    8. virtual void renderSymbols( QPainter *painter, const QPointF *point, int numPoints ) const
    9. {
    10. double symbolWidth = this->size().width();
    11. painter->save();
    12. painter->translate(symbolWidth*0.5,0.0);
    13. QwtSymbol::renderSymbols(painter,point,numPoints);
    14. painter->restore();
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    Does exactly what I want, very satisfactory.

    Best Regards,
    Mikhail

Similar Threads

  1. Adding markers to oscilloscope example
    By espresso in forum Qwt
    Replies: 0
    Last Post: 7th February 2016, 03:29
  2. Replies: 5
    Last Post: 20th August 2012, 21:50
  3. Qwt How to plot our specific symbols?
    By sonulohani in forum Newbie
    Replies: 3
    Last Post: 28th May 2012, 08:48
  4. Help: How to draw markers on plot?
    By jwieland in forum Qwt
    Replies: 5
    Last Post: 24th November 2009, 12:22
  5. Replies: 2
    Last Post: 27th October 2009, 14:40

Tags for this Thread

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.