Qt QCustomPlot 데이터 추출, 마우스 이동 표시

3630 단어
데이터 추출:
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); }

 
전재 대상:https://www.cnblogs.com/caiyingyong/p/10033681.html

좋은 웹페이지 즐겨찾기