Results 1 to 5 of 5

Thread: QwtPlotLegend only uses one column

  1. #1
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1

    Default QwtPlotLegend only uses one column

    Hello,

    I'm trying to include a legend with multiple columns on top of my plot, but only one ever appears.

    Here's the code for adding a new data set (part of a member function of a class that inherits QwtPlot):

    Qt Code:
    1. QwtPlotCurve* curve = new QwtPlotCurve(var->get_name());
    2. curve->attach(this);
    3. plotLayout()->setLegendPosition(QwtPlot::TopLegend);
    To copy to clipboard, switch view to plain text mode 

    but every time I add a curve, the legend gets a new item directly underneath the old one. I have no other legend-related code anywhere, and there is plenty of space for 2-3 more legend items before adding another row. I'm using Qwt-5.2.1.

    How do I get legend items to appear in multiple columns above my plot?

    Thanks,
    Tom

  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: QwtPlotLegend only uses one column

    Use QwtPlot::insertLegend.

    Uwe

  3. #3
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1

    Default Re: QwtPlotLegend only uses one column

    I'm not sure how to use insertLegend to fix the problem.

    In the constructor for my child of QwtPlot, I added

    Qt Code:
    1. insertLegend(new QwtLegend(canvas()), QwtPlot::TopLegend);
    2. plotLayout()->setLegendPosition(QwtPlot::TopLegend);
    To copy to clipboard, switch view to plain text mode 

    but that didn't change anything. I tried adding widgets directly to the legend:

    Qt Code:
    1. QwtPlotCurve* curve = new QwtPlotCurve(var->get_name());
    2. plotLayout()->setLegendPosition(QwtPlot::TopLegend);
    3. legend()->insert(curve, new QLabel("hello", legend()));
    4. curve->attach(this);
    To copy to clipboard, switch view to plain text mode 

    but the QLabels are still stacking up on top of each other, without using different columns.

    Note: Despite setting the QwtLegend to the top position in the constructor, if I don't use setLegendPosition each time I add a curve, the legend appears on the right side of the plot.

    I've tried playing with different ratio parameters, but those did not do anything.

    What am I missing?

    Thanks,
    Tom

  4. #4
    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: QwtPlotLegend only uses one column

    Check the bode example and replace QwtPlot::BottomLegend by QwtPlot::TopLegend.

    If this is what you are looking for check your code and remove everything you did, what has to do with the legend - beside the line you find in the example.

    Uwe

  5. #5
    Join Date
    Apr 2011
    Posts
    9
    Thanks
    1

    Default Re: QwtPlotLegend only uses one column

    Got it! The problem was another piece of code that also inserted a legend. So even though in the constructor I had the correct code, the class constructing my plot called

    Qt Code:
    1. new_plot->insertLegend(new QwtLegend());
    To copy to clipboard, switch view to plain text mode 

    I'm still not sure how I got items in a single column in the top legend.

Similar Threads

  1. Replies: 3
    Last Post: 5th May 2011, 14:03
  2. Get Column Name from a QSqlQueryModel
    By sgmurphy19 in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2007, 23:20
  3. Column with numbers
    By ederbs in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 22:03
  4. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 07:48
  5. Column Colour
    By sumsin in forum Qt Programming
    Replies: 8
    Last Post: 15th June 2006, 10:38

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.