PDA

View Full Version : Accessing Individual Elements of QwtLegend



kedar
26th September 2012, 00:49
Hello,

I am new to Qwt and Qt and require using Qwt to draw a minimum of 15 plots, however I needed to fix the size of the qwtplot. Setting the size of the qwtplot does not adjust the size of the legend. The large number of plots thus results in a large legend accompanied by a scrollbar which is undesirable. Setting the font size of the legend items also does not solve the issue. I would like to know how to access individual legend items in order to set their spacing to zero. Converting the legend to a list like:

QList<QWidget*> this->legend()->legendItems(), gives a list of QWidgets and not QwtLegendItems and hence I cannot use the method setSpacing to set their spacing.

I would further like to access individual legendItems to use their signals (clicked()) in order to highlight individual plots. Both of these problems can be solved if I would know how to access the legendItems.

Please do help me out.

Uwe
26th September 2012, 06:54
I am new to Qwt and Qt and require using Qwt to draw a minimum of 15 plots, ...
Guess you mean one plot with a minimum of 15 curves ?


...however I needed to fix the size of the qwtplot.
The legend is part of a QwtPlot widget - guess you mean you want to have a minimum size for the plot canvas. If true the ratio parameter of QwtPlot::insertLegend might be what you are looking for.


The large number of plots thus results in a large legend accompanied by a scrollbar which is undesirable.
And what type of legend would you like to have instead ?


I would further like to access individual legendItems to use their signals (clicked()) in order to highlight individual plots.
See:


QwtPlot::legendClicked( QwtPlotItem * );Uwe

kedar
26th September 2012, 18:34
Thanks for replying Uwe,


And what type of legend would you like to have instead ?


I apologize for not making myself clear (and for my English). My application consists of drawing a minimum of 15 curves on a single plot. As the number of curves increases, the plot does get cluttered and even though I use some intelligent technique to assign each curve a color, it is impossible to make out which curve say 'x' in the legend corresponds to a curve in the plot. Hence I needed to use signals that when a given legendItem is clicked, the respective curve gets thickened.

I did try changing the aspect ratio of the legend;

QwtLegend* legend = this->legend();
this->insertLegend(legend,QwtPlot::RightLegend,0.3);

I am not sure of how the ratio affects the legend because below 0.1 the legend just disappears and above this the aspect ratio remains same. The size of the curve is 500 px by 500 px and more than 20 items do not fit in this space, a scrollbar is thus created. Is there a way to fix the spacing between the legend items, so as to avoid this from happening. Please see the attached snapshot (ignore the naming of the curves, there are about 33 in this plot8257)


Thanks

Kedar

wysota
26th September 2012, 20:51
The legend (or actually its contentsWidget) has a layout thus you should be able to access it and reduce the spacing.

This should work:

QwtLegend *legend = ...;
legend->contentsWidget()->layout()->setSpacing(1); // or 0

Uwe
27th September 2012, 06:46
Also each legend item has a margin of 4 pixels, that can be modified by QwtTextLabel::setMargin().

Uwe

kedar
27th September 2012, 14:29
Thanks Uwe, Wysota. Works for me.


Kedar