Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Create cursor #Qcustomplot
Forum Update on Monday, May 27th 2025

Create cursor #Qcustomplot

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 698 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Albator
    wrote on 30 Apr 2020, 13:50 last edited by
    #1

    Hello all :)

    I would like to create a cursor that could indicate the points of a curve with the click of a mouse, and also to be able to move the cursor over the curve, even if it is possible to enter a value and the cursor goes to that value.

    I looked a bit at the QCPItemLine library (QCustomPlot *parentPlot) but I don't know if this is the right direction.

    For now I just have this piece of code to plot my graph:

     ui->plot->addGraph();
        ui->plot->graph(0)->setData(batch[i],batch1[i]);
        // give the axes some labels:
        ui->plot->xAxis->setLabel("batch 0");
        ui->plot->yAxis->setLabel("batch 1");
        // set axes ranges, so we see all data:
        ui->plot->xAxis->setRange(0, *std::max_element(batch[i].constBegin(), batch[i].constEnd())+1);
        ui->plot->yAxis->setRange(0, *std::max_element(batch1[i].constBegin(), batch1[etag].constEnd())+1);
        ui->plot->replot();
        ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom );
    
    

    if you have any advice or ideas, I'll take it!

    good day to all :)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Albator
      wrote on 19 May 2020, 12:21 last edited by
      #2

      for a static cursor you can use this code :

       bool ok=true;
      
             tracer_test=new QCPItemTracer(ui->graph5);
          // generate some data:
             QVector<double> x(101), y(101); // initialize with entries 0..100
             double k=0.5;
             for (int i=0; i<101; ++i)
             {
               x[i] = i/50.0 - 1; // x goes from -1 to 1
               y[i] = x[i]*x[i]; // let's plot a quadratic function
             }
             // create graph and assign data to it:
      
             test_QCPGraph=ui->graph5->addGraph();
             test_QCPGraph->setData(x,y);
             test_QCPGraph->setPen(QPen(Qt::blue));
             test_QCPGraph->rescaleKeyAxis();
      
             //ui->graph5->addGraph();
      
             ui->graph5->graph(0)->addData(x,y);
      
      
      
      
             // give the axes some labels:
             ui->graph5->xAxis->setLabel("x");
             ui->graph5->yAxis->setLabel("y");
             // set axes ranges, so we see all data:
             ui->graph5->xAxis->setRange(-1, 1);
             ui->graph5->yAxis->setRange(0, 1);
      
             tracer_test->setGraph(test_QCPGraph);
             tracer_test->setGraphKey(k);
             tracer_test->setInterpolating(ok);
             tracer_test->setStyle(tracer_test->tsCircle);
      
             ui->graph5->replot();
             ui->graph5->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables );
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved