Results 1 to 3 of 3

Thread: updating Widget doesn't work

  1. #1
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: updating Widget doesn't work

    Hello

    I created two windows: "PlotWindow" and "TableWindow"
    330.jpg

    When I click on the button "Show Plot" I expect to see a new graph:
    Qt Code:
    1. void PlotWindow::slotUpdatePlot(const QSqlTableModel &model)
    2. {
    3. int rowCount = model.rowCount();
    4. QVector<double> x( rowCount ), y( rowCount ); // initialize with entries 0..100
    5.  
    6. QSqlRecord record;
    7. for ( int row = 0; row < rowCount; ++row ) {
    8. record = model.record( row );
    9. x[row] = record.fieldName( 0 ).toDouble();
    10. y[row] = record.fieldName( 1 ).toDouble();
    11. }
    12.  
    13. // create graph and assign data to it:
    14. ui->plotWidget->addGraph();
    15. ui->plotWidget->graph( 0 )->setData( x, y );
    16. // give the axes some labels:
    17. ui->plotWidget->xAxis->setLabel( "x" );
    18. ui->plotWidget->yAxis->setLabel( "y" );
    19. // set axes ranges, so we see all data:
    20. ui->plotWidget->xAxis->setRange( -1, 1 );
    21. ui->plotWidget->yAxis->setRange( 0, 1 );
    22.  
    23. ui->plotWidget->update();
    24. }
    To copy to clipboard, switch view to plain text mode 

    How you can see below I wrote: ui->plotWidget->update();

    But when I resize my PlotWindow I see the right result:
    331.jpg


    Added after 7 minutes:


    This is my source code: https://github.com/8Observer8/PlotAndTable
    Last edited by 8Observer8; 5th September 2014 at 13:47.

  2. #2
    Join Date
    Sep 2014
    Location
    Sydney, Australia
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: updating Widget doesn't work

    You should use:
    Qt Code:
    1. ui->plotWidget->replot();
    To copy to clipboard, switch view to plain text mode 
    to update the plot immediately.

    update() will not call the QCustomPlot's paint event until you resize/click etc.
    HTH.
    "When the only tool you have is a hammer, every problem resembles a nail"

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

    8Observer8 (12th September 2014)

  4. #3
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: updating Widget doesn't work

    Thank you very much! It is excellent!

Similar Threads

  1. Replies: 1
    Last Post: 24th May 2011, 17:29
  2. why QT layout doesn't work on the second widget?
    By Kevin Hoang in forum Qt Programming
    Replies: 9
    Last Post: 20th March 2010, 21:29
  3. updating a widget's display
    By jhearon in forum Qt Programming
    Replies: 5
    Last Post: 10th November 2008, 16:59
  4. submitAll() not work for updating fields
    By brokensword in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2008, 12:02

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.