Results 1 to 4 of 4

Thread: Problem with passing a value from lineedit to a graph

  1. #1
    Join Date
    Feb 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Question Problem with passing a value from lineedit to a graph

    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.

    Thank you for your time and knowledge.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with passing a value from lineedit to a graph

    Try:

    Qt Code:
    1. lineX->setVisible( true );
    To copy to clipboard, switch view to plain text mode 

    etc.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    pj0909 (14th February 2017)

  4. #3
    Join Date
    Feb 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with passing a value from lineedit to a graph

    Hi d_stranz,

    Thank you for the reply.

    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.

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with passing a value from lineedit to a graph

    Thanks for sharing your solution so others who come across this thread might be helped.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Problem with graph drawing
    By Rizo Isrof in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2011, 13:06
  2. Problem to plot 3D graph using QWT
    By johnMick in forum Qwt
    Replies: 4
    Last Post: 26th July 2011, 10:44
  3. LineEdit / SpinBox focus in problem
    By Sethest in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2008, 14:06
  4. Problem with Drag Drop for QWT Graph
    By Ankitha Varsha in forum Qwt
    Replies: 2
    Last Post: 23rd January 2008, 06:21
  5. General lineEdit, converting problem
    By Salazaar in forum Newbie
    Replies: 28
    Last Post: 18th June 2007, 17:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.