steve123
16th May 2011, 20:58
I've got a plot with a legend that initially appears ok. However, when I click on an item in the legend to deselect it (uncheck it?) it is not only unchecked, but it disappears from the legend entirely. Furthermore, I never get a signal when an item on the legend is clicked.
Here is part of my code (I have left out quite a bit of code from this class):
In the constructor of my class, plot_ is a QwtPlot*:
QwtLegend * legend = new QwtLegend();
legend->setItemMode(QwtLegend::CheckableItem);
legend->setWhatsThis("Click on an item to show/hide the plot");
plot_->insertLegend(legend, QwtPlot::RightLegend);
connect(plot_, SIGNAL(legendChecked(QwtPlotItem *, bool)),this,
SLOT(showCurve(QwtPlotItem *, bool)));
Later on, when I add a new curve (newSpec is a QwtPlotSpectrogram* ):
newSpec->setItemAttribute(QwtPlotItem::Legend, true); // add to the clickable legend
newSpec->updateLegend(plot_->legend());
I assume the two problems (signal not set up correctly, items disappearing) are related but I can't figure out why or how to solve it. Thank you very much!
Edit: forgot to mention, if this helps, the itemCount() of the legend does change (decreases by 1) when one of the legend items disappears.
Here is part of my code (I have left out quite a bit of code from this class):
In the constructor of my class, plot_ is a QwtPlot*:
QwtLegend * legend = new QwtLegend();
legend->setItemMode(QwtLegend::CheckableItem);
legend->setWhatsThis("Click on an item to show/hide the plot");
plot_->insertLegend(legend, QwtPlot::RightLegend);
connect(plot_, SIGNAL(legendChecked(QwtPlotItem *, bool)),this,
SLOT(showCurve(QwtPlotItem *, bool)));
Later on, when I add a new curve (newSpec is a QwtPlotSpectrogram* ):
newSpec->setItemAttribute(QwtPlotItem::Legend, true); // add to the clickable legend
newSpec->updateLegend(plot_->legend());
I assume the two problems (signal not set up correctly, items disappearing) are related but I can't figure out why or how to solve it. Thank you very much!
Edit: forgot to mention, if this helps, the itemCount() of the legend does change (decreases by 1) when one of the legend items disappears.