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. Trouble with passing a value from lineedit to a Graph
Forum Updated to NodeBB v4.3 + New Features

Trouble with passing a value from lineedit to a Graph

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 596 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pj0909
    wrote on last edited by
    #1

    Hi All,

    I am new to Qt and started exploring some of its features. I am stuck in a problem. In the form.ui I have a lineedit, a push button and a widget (promoted to QCustomPlot). My requirement is when a value is entered in lineedit and after push button is pressed, it should create a line on the graph. My code is -

    void Form:n_refForceValueButton_clicked()
    {
    float ref_force_value = ui->lineEdit->text().toFloat(); // to read the value entered in line edit in form.ui
    
    // to take the value of lineedit and pass on to y co-ordinate of graph to have a straight line
    QCPItemLine *lineX = new QCPItemLine(ui->customPlotX);
    lineX->start->setCoords(0,ref_force_value);
    lineX->end->setCoords(1000000,ref_force_value);
    lineX->setPen(QPen(Qt::black));
    
    QCPItemLine *lineY = new QCPItemLine(ui->customPlotY);
    lineY->start->setCoords(0,ref_force_value);
    lineY->end->setCoords(1000000,ref_force_value);
    lineY->setPen(QPen(Qt::black));
    
    QCPItemLine *lineZ = new QCPItemLine(ui->customPlotZ);
    lineZ->start->setCoords(0,ref_force_value);
    lineZ->end->setCoords(1000000,ref_force_value);
    lineZ->setPen(QPen(Qt::black));
    
    QCPItemLine *line = new QCPItemLine(ui->customPlot);
    line->start->setCoords(0,ref_force_value);
    line->end->setCoords(1000000,ref_force_value);
    line->setPen(QPen(Qt::black));
    
    if (ref_force_value>0)
    {
    QString msg = "Reference Force Value is set to " + QString::number(ref_force_value) + "mN."; // to combine     string and float
    
    QMessageBox::information(this, "Reference Force Value", msg); // to pop-up window displaying message when button is clicked
    }
    }
    

    As you can see from the code I have 4 widgets (all promoted to QCustomPlot). When I enter the value in lineedit and click the button it works well with pop-up window and it displays the message but it doesn't pass the value entered in lineedit on to the graph. Can anyone please guide me on my code. I am using Qt5.8 on Windows 10 with MinGW compiler.

    Thank you for your time and knowledge.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome
      Just as a note: QCustomPlot is not part of Qt :)

      I have used it however and its unclear if you have all the other needed code in place

      If you see here
      http://www.qcustomplot.com/index.php/tutorials/basicplotting

      There is
      // create graph and assign data to it:
      customPlot->addGraph();
      customPlot->graph(0)->setData(x, y)

      which is critical and so on :)

      1 Reply Last reply
      3
      • P Offline
        P Offline
        pj0909
        wrote on last edited by
        #3

        Hi mrjj,

        Thank you for the reply. Yes, I have all the essentials of QCustomPlot.

        I figured out the solution. I didn't set the linestyle and scatterstyle therefore I was not able to see the plot as it was by default in white color. Once those parameters are set I can see the plot now and it works as expected.

        1 Reply Last reply
        1

        • Login

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