PDA

View Full Version : updating Widget doesn't work



8Observer8
5th September 2014, 13:47
Hello

I created two windows: "PlotWindow" and "TableWindow"
10615

When I click on the button "Show Plot" I expect to see a new graph:


void PlotWindow::slotUpdatePlot(const QSqlTableModel &model)
{
int rowCount = model.rowCount();
QVector<double> x( rowCount ), y( rowCount ); // initialize with entries 0..100

QSqlRecord record;
for ( int row = 0; row < rowCount; ++row ) {
record = model.record( row );
x[row] = record.fieldName( 0 ).toDouble();
y[row] = record.fieldName( 1 ).toDouble();
}

// create graph and assign data to it:
ui->plotWidget->addGraph();
ui->plotWidget->graph( 0 )->setData( x, y );
// give the axes some labels:
ui->plotWidget->xAxis->setLabel( "x" );
ui->plotWidget->yAxis->setLabel( "y" );
// set axes ranges, so we see all data:
ui->plotWidget->xAxis->setRange( -1, 1 );
ui->plotWidget->yAxis->setRange( 0, 1 );

ui->plotWidget->update();
}

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

But when I resize my PlotWindow I see the right result:
10616

Added after 7 minutes:

This is my source code: https://github.com/8Observer8/PlotAndTable

Nomad_Tech
12th September 2014, 10:55
You should use:

ui->plotWidget->replot();
to update the plot immediately.

update() will not call the QCustomPlot's paint event until you resize/click etc.
HTH.

8Observer8
12th September 2014, 11:40
Thank you very much! It is excellent! :D