Results 1 to 4 of 4

Thread: Place a chart's legend inside an ancestor

  1. #1
    Join Date
    Jan 2013
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Place a chart's legend inside an ancestor

    I'd like to take a chart's legend and place it inside one of the chart's siblings. The idea is that I have several charts laid out horizontally which all share the same range (y axis).

    In this particular case, my widget hierarchy looks something like this:

    ...
    - QSplitter
    - - QwtPlot
    - - - QwtLegend
    - - QwtPlot
    - - - QwtLegend
    - - QwtPlot
    - - - QwtLegend

    The legends are all redundant, so it wastes a lot of space. I'd rather it look something like this:

    ...
    - QSplitter
    - - QwtLegend
    - - QwtPlot
    - - QwtPlot
    - - QwtPlot

    Can this be done? How?


    Added after 8 minutes:


    It looks like QwtPlot doesn't even provide a way to remove a legend once it's been added.
    Last edited by stephelton; 9th January 2013 at 08:23.

  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: Place a chart's legend inside an ancestor

    You might want to use Qwt 6.1 with its new architecture for the plot legends. A legend ( could be a QwtLegend, but any other widget as well - see the stockchart example ) simply connects to a signal of the plot:

    Qt Code:
    1. void legendDataChanged( const QwtPlotItem *plotItem, const QList<QwtLegendData> &data)
    To copy to clipboard, switch view to plain text mode 
    QwtPlot::insertLegend() is still available to insert the legend into the layout system of a plot, but this is optionally. You could also put a legend somewhere in your application layout and connect as many plots as you want to it - by doing the signal/slot connections manually.

    3 notes:

    • QwtPlot::ExternalLegend has to be replaced by not inserting the legend and setting up the signal/slots connection manually
    • Don't be confused, that legendDataChanged emits a list of entries for one plot item. Usually the list will have 1 or 0 entries, but f.e. QwtPlotMultiBarChart needs to show more than entry.
    • Unfortunately I will have to modify the API of QwtLegend, so that Qwt 6.1 will be usable for the qwtpolar package as well. But the only consequence for application code will be, that it might have to add some casts for QwtPlotItem.


    Uwe

    PS: A inserted legend can be removed by: QwtPlot::insertLegend( NULL ).
    Last edited by Uwe; 9th January 2013 at 09:20.

  3. #3
    Join Date
    Jan 2013
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Place a chart's legend inside an ancestor

    Thanks for the quick reply. I'll try out QWT 6.1, should be no problem for my project.

    I tried calling QwtPlot::insertLegend( NULL ). but I get segfault when I do that (svn 6.0.3).

  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: Place a chart's legend inside an ancestor

    Quote Originally Posted by stephelton View Post
    I tried calling QwtPlot::insertLegend( NULL ). but I get segfault when I do that (svn 6.0.3).
    Should be a problem of your code - ask your debugger.

    Qwt 6.1 also comes with a new example called legends, that plays with legends - including a new plot item for displaying a legend on the canvas.

    Uwe

Similar Threads

  1. Replies: 5
    Last Post: 26th October 2012, 09:46
  2. Replies: 2
    Last Post: 2nd December 2011, 16:43
  3. Replies: 3
    Last Post: 8th December 2010, 06:42
  4. legend inside qwt plot
    By kaustav98255 in forum Qwt
    Replies: 5
    Last Post: 11th February 2009, 21:39
  5. Inherit size from ancestor Widget/QFrame
    By SenSej in forum Newbie
    Replies: 4
    Last Post: 26th September 2008, 12:55

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.