Yes, QCoreApplication::processEvents() works, but I have also found that calling QwtPlot::replot() before rendering the plot have the same effect. This code produces a normally looking image:
QwtPlotRenderer renderer;
plot->replot();
renderer.
renderDocument(plot, fileName,
QSizeF(100,
100));
QwtPlotRenderer renderer;
plot->replot();
renderer.renderDocument(plot, fileName, QSizeF(100, 100));
To copy to clipboard, switch view to plain text mode
I have tested two cases, in the first the scales are set to 0-1 and 0-180, and in the second there is no code setting the scales. The whole block of code creating the plot is within a single method and looks like this:
plot
->setAxisScale
(QwtPlot::xBottom,
0,
180);
plot
->setAxisScale
(QwtPlot::yLeft,
0,
1);
curve->setTitle("Test");
curve->setPen(Qt::blue, 2 );
curve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
curve->setSamples(data->getProbabilityCurve());
curve->attach(plot);
QwtPlotRenderer renderer;
plot->replot();
renderer.
renderDocument(plot, fileName,
QSizeF(100,
100));
QwtPlot* plot = new QwtPlot();
plot->setAxisScale(QwtPlot::xBottom, 0, 180);
plot->setAxisScale(QwtPlot::yLeft, 0, 1);
QwtPlotCurve* curve = new QwtPlotCurve();
curve->setTitle("Test");
curve->setPen(Qt::blue, 2 );
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
curve->setSamples(data->getProbabilityCurve());
curve->attach(plot);
QwtPlotRenderer renderer;
plot->replot();
renderer.renderDocument(plot, fileName, QSizeF(100, 100));
To copy to clipboard, switch view to plain text mode
Commenting plot->replot() call leads to scales reset. Commenting plot->setAxisScale calls has no effect on resetting.
Bookmarks