qcustomplot之如何在界面中画游标(部分项目)

最近在用qcustomplot做一个项目,记录一下,也是怕自己忘记
图一:实现的效果图。
在这里插入图片描述
使用鼠标移动触发。(部分项目代码,自己在家没事的时候,折腾出来的,不涉及公司的代码)

实现的功能 鼠标右键后 释放(线段不随随便的移动而移动)
   if(ui->customPlot->graph(1)->selected() && mflag.axisMflag_x1==2)
                 {
                     mflag.axisMflag_x1 = 3; //=3的时候是不随游标进行移动
                 }
                 else if(mflag.axisMmflag_x1 == 1 ) //进行了第一次
                 {
                     mflag.axisMflag_x2 = 3;
                 }
功能 鼠标移动后,游标随鼠标的移动而移动,不过前提是要先选中。
void MainWindow::showTracer(QMouseEvent *event)
{
    double double_x = ui->customPlot->xAxis->pixelToCoord(event->pos().x()) ;
    double double_y = ui->customPlot->yAxis->pixelToCoord(event->pos().y()) ;
    cursor_x =  double_x  ;//获得当前鼠标的位置
    cursor_y =  double_y  ;//获得当前鼠标的位置
    showCursor() ;
}
void MainWindow::triggerCurrentLine(double y)
{
    if( mflag.axisMflag_x1 == 1 )
    {
        y1_cursorData =  cursor_y;
        cursorX4[0] =  ui -> customPlot->xAxis->range().upper ;
        cursorX4[1] =  ui -> customPlot->xAxis->range().lower ;
        cursorY4[0] =   y1_cursorData ;
        cursorY4[1] =   y1_cursorData ;

        ui->customPlot->graph(1)->setData( cursorX4,  cursorY4 );
        ui->lineEdit_TrigerUnit->setText( QString::number( y1_cursorData ,'f', 1)) ;
    }
    else if( mflag.axisMflag_x1 == 3 )  // 查看鼠标右键
    {
        if( ui->customPlot->graph(1)->selected() )
        {
            y1_cursorData =  cursor_y;
            cursorX4[0] =  ui -> customPlot->xAxis->range().upper ;
            cursorX4[1] =  ui -> customPlot->xAxis->range().lower ;
            cursorY4[0] =   y1_cursorData ;
            cursorY4[1] =   y1_cursorData ;
            ui->customPlot->graph(1)->setData( cursorX4,  cursorY4 );
            qDebug("%f",y1_cursorData);

        }
        else
        {
            cursorX4[0] =  ui -> customPlot->xAxis->range().upper ;
            cursorX4[1] =  ui -> customPlot->xAxis->range().lower ;
            cursorY4[0] =   y1_cursorData ;
            cursorY4[1] =   y1_cursorData ;
            ui->customPlot->graph(1)->setData(cursorX4, cursorY4) ;
            qDebug("%f",y1_cursorData);
        }
        ui->lineEdit_TrigerUnit->setText( QString::number( y1_cursorData ,'f', 1)) ;
    }
    else if (mflag.axisMflag_x3 ==  0)
    {
        cursorX4[0] = 0 ;
        cursorX4[1] = 0 ;
        cursorY4[0] = 0 ;
        cursorY4[1] = 0 ;
        ui->customPlot->graph(1)->setData(cursorX4, cursorY4);
        ui->lineEdit_TrigerUnit->setText( QString::number( 0,'f', 1)) ;
    }

    switch (ui->y_unit_comboBox->currentIndex())
    {
       case 0 : ui->comboBoxTrigerUnit->setCurrentIndex(0);break;
       case 1:  ui->comboBoxTrigerUnit->setCurrentIndex(1);break;
       case 2:  ui->comboBoxTrigerUnit->setCurrentIndex(2); break;
      default: break;
    }

}
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

七 六 伍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值