取数据:
for (int i = 0;i < ui->plot->graph(0)->dataCount();i++) { float x = ui->plot->graph(0)->data()->at(i)->key; float y = ui->plot->graph(0)->data()->at(i)->value; qDebug() << x << y << endl; }
鼠标移动:
connect(ui->plot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(myMoveEvent(QMouseEvent*))); void MainWindow::myMoveEvent(QMouseEvent *event) { //获取鼠标坐标,相对父窗体坐标 int x_pos = event->pos().x(); int y_pos = event->pos().y(); //鼠标坐标转化为CustomPlot内部坐标 float x_val = ui->plot->xAxis->pixelToCoord(x_pos); float y_val = ui->plot->yAxis->pixelToCoord(y_pos); QString str,strToolTip; str = QString::number(x_val, 10, 3); strToolTip += "x: "; strToolTip += str; strToolTip += " "; for (int i = 0;i < ui->plot->xAxis->graphs().count();i++) { //获得x轴坐标位置对应的曲线上y的值 float y = ui->plot->graph(i)->data()->at(x_val)->value; str = QString::number(y); strToolTip += "y" + QString::number(i) + ":"; strToolTip += str; strToolTip += " "; } QToolTip::showText(cursor().pos(), strToolTip, ui->plot); }