QCustomPlot版本:Version: 2.1.1

  1. 设置点选择模式
customPlot->setInteractions(QCP::iSelectPlottables);

2.绑定点击事件

connect(customPlot,  &QCustomPlot::plottableClick, this, &CCustomPlot::onPlotClick);

3.读取点位置

void CustomPlot::onPlotClick(QCPAbstractPlottable *plottable, int dataIndex, QMouseEvent *event)
{
    QStringList nameList = plottable->name().split(" ");
    if( nameList.count()>1 &&  nameList.at(1).toInt()>0)
    {
        int graphId = nameList.at(1).toInt();
        const QCPGraphData *ghd = customPlot->graph(graphId-1)->data()->at(dataIndex);
        qDebug()  << "key:"<< ghd->key  <<" value:"<< ghd->value;
    }
}
08-03 16:54