PDA

View Full Version : QwtPlotLegend only uses one column



orignihn
16th May 2011, 19:05
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):



QwtPlotCurve* curve = new QwtPlotCurve(var->get_name());
curve->attach(this);
plotLayout()->setLegendPosition(QwtPlot::TopLegend);


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

Uwe
16th May 2011, 20:00
Use QwtPlot::insertLegend.

Uwe

orignihn
16th May 2011, 21:28
I'm not sure how to use insertLegend to fix the problem.

In the constructor for my child of QwtPlot, I added



insertLegend(new QwtLegend(canvas()), QwtPlot::TopLegend);
plotLayout()->setLegendPosition(QwtPlot::TopLegend);


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



QwtPlotCurve* curve = new QwtPlotCurve(var->get_name());
plotLayout()->setLegendPosition(QwtPlot::TopLegend);
legend()->insert(curve, new QLabel("hello", legend()));
curve->attach(this);


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

Uwe
17th May 2011, 06:48
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

orignihn
17th May 2011, 14:27
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



new_plot->insertLegend(new QwtLegend());


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