In your interaction-example, edit the
addRandomGraph function in this way:
ui->customPlot->addGraph(); ui->customPlot->graph()->setName(QString("New graph %1").arg(ui->customPlot->graphCount()-1)); //ui->customPlot->graph()->setData(x, y); ui->customPlot->graph()->setLineStyle((QCPGraph::LineStyle)(rand()%5+1));
When you run it, you will still have 4 random graph, which their names shown in the legend but with no data.
Now, select a graph in the legend and right-click to show the context menu. You will see the "Remove selected graph" item is missing.
This is because
customPlot->selectedGraphs().size() is 0.
How to remove a graph that contains no data? It actually exists because it is shown in the legend...