QCustomplot - 隐藏/显示选定的图形

QCustomplot - Hide / Show selected graph

我想通过直接在绘图上选择来隐藏/显示图表。我的想法是这样的:

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

其中 myPlot 是一个 QCustomPlot 小部件。

我的问题是:有没有办法获取所选图形的索引graphIdx?这可能是微不足道的,但老实说我无法弄清楚。

提前致谢

A.

使用函数 QCustomPlot::selectedGraphs that returns a QList<QCPGraph *> (在你的情况下它应该正好有 1 个元素)。您可以在这些指针上直接调用 setVisible。您可能需要 QCustomPlot::selectedPlottables 而不是文档建议的那样。

我想你可以从 QCustomPlot::selectedGraphs() 中获取指针。

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