Hello!
When QCustomPlot customized like this (without QCP::iSelectPlottables)
ui->customPlot->setInteractions(QCP::iSelectLegend);
graph is selected via click on legend item , but when I click on another legend item previous graphs remains selected.
Is this a correct behavior?
My goal is to let user to select a graph only through legend click. And only one graph can be selected.
Here is my code now:
void KTab::legendClick(QCPLegend * legend, QCPAbstractLegendItem * item, QMouseEvent * event) { Q_UNUSED(event) for (int i = 0; i < legend->itemCount(); ++i) { QCPAbstractLegendItem * item = legend->item(i); QCPPlottableLegendItem * legendItem = qobject_cast<QCPPlottableLegendItem *>(item); legendItem->plottable()->setSelected(false); } if (item) // only react if item was clicked (user could have clicked on border padding of legend where there is no item, then item is 0) { QCPPlottableLegendItem * legendItem = qobject_cast<QCPPlottableLegendItem *>(item); legendItem->plottable()->setSelected(true); } ui->customPlot->replot(); }