qcustomplot画鼠标十字星

本文介绍了一个使用Qt框架实现的鼠标移动事件处理方法。通过监听鼠标移动,更新自定义图表中垂直和水平辅助线的位置,使得用户能够直观地看到鼠标所处位置的数据坐标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void MainWindow::mouseMoved(QMouseEvent*event)
{
    QVector<double> vx,vy;
    double x = ui->customPlot->xAxis->pixelToCoord(event->pos().x());
    double y = ui->customPlot->yAxis->pixelToCoord(event->pos().y());
    vx<<0<<x<<ui->customPlot->xAxis->range().maxRange;
    vy<<y<<y<<y;

    ui->customPlot->graph(1)->setData(vx,vy);
    ui->customPlot->graph(1)->setPen(QPen(Qt::red));

    vx.clear();
    vy.clear();
    vx<<x<<x<<x;
    vy<<0<<y<<ui->customPlot->yAxis->range().maxRange;
    ui->customPlot->graph(2)->setData(vx,vy);
    ui->customPlot->graph(2)->setPen(QPen(Qt::red));
    ui->customPlot->replot();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值