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*:
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,
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)));
To copy to clipboard, switch view to plain text mode
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());
newSpec->setItemAttribute(QwtPlotItem::Legend, true); // add to the clickable legend
newSpec->updateLegend(plot_->legend());
To copy to clipboard, switch view to plain text mode
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.
Bookmarks