简体   繁体   中英

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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM