PDA

View Full Version : qwtlegend



Surfman19
5th August 2015, 14:47
Hi,

i use a QwtPlot with a QwtPlotShapeItem...




QPainterPath path;
path.addRect(....);

plotShapeItem.setRenderHint(QwtPlotItem::RenderAnt ialiased, true);
plotShapeItem.setShape(path);
plotShapeItem.setItemAttibute(QwtPlotItem::Legend, true);
plotShapeItem.setLegendMode(QwtPlotShapeItem::Lege ndShape);
plotShapeItem.setLegendIconSize(QSize(20, 20));
plotShapeItem.setTitle(QString("Winter"));
plotShapeItem.attach(&plot);


how can i make the legend for plotShapeItem enabled? I dont know how to config the QwtLegend in this case... See here:
11306

I would need the QwtLegendLabel and call setchecked(true)...ideas?

Thanks,
S

Uwe
5th August 2015, 17:13
Have a look at the itemeditor example.

Uwe

Surfman19
5th August 2015, 20:46
i cannot find the relevant part....which file and line do you mean?

i only found this part, which looks similar what i do: https://github.com/sikoragmbh/qwt/blob/master/tags/qwt-6.1.0/qwt/examples/itemeditor/plot.cpp#L92:#L107
i dont see QwtLegendLabel calling setchecked in this code...ideas?

Surfman19
6th August 2015, 08:02
sorry for the confusion....
i have upated the image... as you see Winter is not enabled in the legend, but the QwtPlotShapeItem is visible (as expected)
i want to enable the QwtLegendLabel for Winter ... therefore i need to get the QwtLegendLabel and call setchecked(true)... ideas?

11308

Surfman19
6th August 2015, 14:23
any idea Uwe?

Uwe
6th August 2015, 16:43
tvplot and cpuplot examples show how to get access the legend label for an item.

When you are wondering, why there is no more obvious getter ( like in earlier Qwt versions ) have a look at the stockchart example, where the legend is replaced by a tree view. It is like with QAbstractItemModel - this mysterious API is the price 99.9% of the applications have to pay to make 0.1% of the use cases possible.

Uwe

Surfman19
6th August 2015, 19:02
ah thaks...i fixed it, i didnt see that itemList takes different parameters: http://qwt.sourceforge.net/class_qwt_plot_item.html#ab149ac85e233ce9cedf2f2f2 af871bf3



QwtPlotItemList items = itemList( QwtPlotItem::Rtti_PlotShape );
for ( int i = 0; i < items.size(); i++ )
{
QwtLegendItem *legendItem = qobject_cast<QwtLegendItem *>( legend->find( items[i] ) );
if ( legendItem ) {
legendItem->setChecked( true );
}

items[i]->setVisible( true );
}