Results 1 to 2 of 2

Thread: Multiple QwtPlotlegends

  1. #1
    Join Date
    Oct 2015
    Posts
    50
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Multiple QwtPlotlegends

    Hi,

    I want to have multiple legends for my plot.
    One legend on the top of my plot which displays 3 or more different QwtPlotZoneItems. When I add them to a legend they are displayed without icon but I need the color of brush/pen because it indicates a certain state.

    I have three (or more) different states. Only one state at once can be active. So the ZoneItem indicates which state is active, e.g.
    red -> first state
    yellow -> second state
    blue -> third state

    I use multiple plots which use the same x-Axis and they all have the same marked Zones. So on top of my plots i want to have a legend indicating which color represents which state.


    Is there a good way to realise this with qwt or do you think i should write an own legend on top of my plots with simple labels and QRects? Are there any examples?

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

    Default Re: Multiple QwtPlotlegends

    One legend on the top of my plot which displays 3 or more different QwtPlotZoneItems. When I add them to a legend they are displayed without icon but I need the color of brush/pen because it indicates a certain state.
    Should be something like this:
    Qt Code:
    1. class YourZoneItem: public QwtPlotZoneItem
    2. {
    3. ....
    4.  
    5. virtual QwtGraphic legendIcon( int, const QSizeF &size ) const override
    6. {
    7. return defaultIcon( brush().color(), size );
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 

    I use multiple plots which use the same x-Axis and they all have the same marked Zones. So on top of my plots i want to have a legend indicating which color represents which state.
    Plots and legends are connected by QwtPlot::legendDataChanged() -> QwtAbstractLegend::updateLegend(). When not using QwtPlot::insertLegend() you are free to put a legend ( or more than one ) wherever you want to - but you have to set up the connection manually. In this case QwtPlotRenderer does not know about your layout and you would have to write some code in case you need to have the legend on a PDF.

    I can imagine, that you have to derive from QwtLegend overloading updateLegend() to sort out certain types of items, you don't want to have on this legend ( for the one on top all beside the zones ).

    It might help to have a look at legend.cpp from the stockchart example, where you can see how to evaluate the parameters of QwtAbstractLegend::updateLegend().

    Uwe

Similar Threads

  1. how to Plot multiple graphs of multiple range ?
    By karankumar1609 in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2013, 11:22
  2. using one signal to update multiple multiple controls
    By henryjoye in forum Qt Programming
    Replies: 7
    Last Post: 13th December 2011, 14:19
  3. Replies: 2
    Last Post: 19th October 2011, 09:30
  4. Replies: 1
    Last Post: 17th May 2011, 16:12
  5. Replies: 0
    Last Post: 21st December 2006, 11:48

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.