tuspazio
tuspazio

Reputation: 213

QCustomplot - Hide / Show selected graph

I'd like to hide / show a graph by selecting it directly on the plot. What I have in mind is something like this:

myPlot->graph(graphIdx)->setVisible(false);

in which myPlot is a QCustomPlot widget.

My question is: is there a way to get the index graphIdx of the selected graph? It might be trivial but honestly I cannot figure it out.

Thanks in advance

A.

Upvotes: 1

Views: 3297

Answers (2)

I think you can just take pointer from QCustomPlot::selectedGraphs().

auto ololo = new QCustomPlot();
...
foreach(QCPGraph* gr, ololo->selectedGraphs()){
    gr->setVisible(false);
}

Upvotes: 1

nwp
nwp

Reputation: 9991

Use the function QCustomPlot::selectedGraphs that returns a QList<QCPGraph *> (in your case it should have exactly 1 element). You can directly call setVisible on those pointers. You may want QCustomPlot::selectedPlottables instead as the documentation suggests.

Upvotes: 3

Related Questions