Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

mouse tracer CustomPlot



  • I must build a mouseTracer like this:
    https://www.youtube.com/watch?v=BzK1DmJPbuk

    my problem it's that my marker follows the graph jerky..i built the graph with a vector x of double numbers and a vector y of randon numbers and I wrote:

    double x = (ui->Grafico->positionX);
    int j;
    double u;
    for (int i=0; i<1000; i++)
    {
    if (abs(xalt[i] - x)<0.1)
    {
    u= xalt[i];
    j=i;

       }
    

    }

    ui->Grafico->positionY = f_altezza[j];
    /QString h= QString::number(x);
    QString a = QString::number(f_altezza[x])
    /

    /*qDebug()<<"x"<<h<<endl;
    qDebug()<<"funz"<<a<<endl;
    qDebug()<<"funz1"<<f_altezza[33]*/
    

    if((ui->Grafico->mouseMarkerX) && (ui->Grafico->mouseMarkerY))
    {
    ui->Grafico->mouseMarkerX->point1->setCoords(ui->Grafico_Altezza_LdC_Acquisizione->positionX, 0);//VERTICALE
    ui->Grafico->mouseMarkerX->point2->setCoords(ui->Grafico_Altezza_LdC_Acquisizione->positionX, 1);//VERTICALE
    ui->Grafico->mouseMarkerY->point1->setCoords(0, ui->Grafico->positionY);//ORIZZONTALE
    ui->Grafico->mouseMarkerY->point2->setCoords(1, ui->Grafico->positionY);//ORIZZONTALE
    }
    ui->Grafico->replot();



  • @mrjj I solved


  • Lifetime Qt Champion

    Hi
    If you call this in mouseMove and
    execute the 1000 loop each time, it might be the reason for it being jerky.



  • @mrjj so how I must do to obtain like in the video


  • Lifetime Qt Champion

    @vale88
    Sorry, i have no idea about that as i dont know the class you used or what you are
    actually doing with it.
    However, to follow the graph data on Y,
    i would assume you would ask the Plotter what y is from an x value.



  • @mrjj I solved


  • Lifetime Qt Champion

    @vale88
    Super :)
    Could you show how you did, so future readers might benefit ?



  • @mrjj

    void MainWindow::Tracer_Acq()

    {

    double x = (Grafico->positionX);
    int j;
    double u;
    double posX;
    
    
    QString h = QString::number(x,'f',2);
    double x1 = h.toDouble();
    for (int i=0; i<1000; i++)
    {
        if  (abs(xalt[i] - x1) <0.001)
        {
    
           u= xalt[i];
           j=i;
    
           Grafico->positionY = f_altezza[j];
           posX = xalt[j];
           if((Grafico->mouseMarkerX) && (Grafico->mouseMarkerY))
    
           {
              Grafico->mouseMarkerX->point1->setCoords(Grafico->positionX, 0);//VERTICALE
              Grafico->mouseMarkerX->point2->setCoords(Grafico->positionX, 1);//VERTICALE
              Grafico->mouseMarkerY->point1->setCoords(0,Altezza_acq_bis->positionY);//ORIZZONTALE
              Grafico->mouseMarkerY->point2->setCoords(1, Grafico->positionY);//ORIZZONTALE
    
    
              QString x_text = QString::number(Grafico->positionX,'f',2);
              QString y_text = QString::number(Grafico->positionY);
    
              QString coord_p = QString("%1, %2").arg(x_text,y_text);
              QCursor cursor;
              QToolTip::showText(cursor.pos(),coord_p,this,QRect(),2000);
    
           }}
    
    
        }
          Grafico->replot();
     }
    

    it isn't completely solved but better I don't know if it's possible


Log in to reply