PDA

View Full Version : QPainter error using qwtPlot



chinalski
10th February 2013, 21:19
Hello,
I'm using qwtPlot and qwtPlotCurve to show diagrams that could be bigger than the video. I have cursors to move through the diagram. Y axis is the time axis and X axis is the amplitude of a signal. It is possible to control a zoom on the Y axis, increasing or reducing the size of the plot, specially on the Y axis.
For example having a curve of 3000 samples I use a 5000 points plot to show it. Everything works well in this case.

If I try to plot the same curve, with the same samples, on a bigger time scale, for example the curve of 3000 samples on a plot of 25000 points, i've got the errors:

QPainter::begin Paint device returned engine == 0, type: 2
QPainter::translate: Painter not active
QPainter::save: Painter not active
QPainter::setClipRct: Painter not active
and so on.
I understood that could be a problem of QPixMap size not exactly defined, but I'm not able to find in the documentation in which way I can set it, because I don't use QPixmap explicitly but only through Qwt classes,
Or maybe is something different that I don't know.

This is the piece of my source code.

QwtPlot * plot = new QwtPlot();
QwtPlotCurve * plotCurve = new QwtPlotCurve();

plot->enableAxis(QwtPlot::xBottom, false);
plot->enableAxis(QwtPlot::yLeft, false);
plot->setCanvasBackground(Qt::white);
plot->setFrameStyle(QFrame::NoFrame);
plot->setCanvasLineWidth(1);
plot->setAxisScale(QwtPlot::yLeft, samplesNumber, 0, 0);
plot->axisScaleDraw(QwtPlot::yLeft);
plot->setMaximumWidth(plotWidth);
plot->setMaximumHeight(plotHeight);

plotCurve->setOrientation(Qt::Horizontal);
plotCurve->setPaintAttribute(QwtPlotCurve::ClipPolygons, true);
plotCurve->setSamples(amplitudeToShowValue[i], tValue);
plotCurve->setPen(QColor(Qt::blue));
plotCurve->setBrush(QBrush(Qt::blue, Qt::SolidPattern));
plotCurve->setBaseline(0);
plotCurve->attach(plot);

Thank you very much for any suggestion,
carlo

Uwe
11th February 2013, 07:17
I'm using qwtPlot and qwtPlotCurve to show diagrams that could be bigger than the video. I have cursors to move through the diagram. Y axis is the time axis and X axis is the amplitude of a signal. It is possible to control a zoom on the Y axis, increasing or reducing the size of the plot, specially on the Y axis.
The solution you are trying to implement will let you run into performance, memory issues and more. Better don't waste any second more on this approach.

If you want to implement zooming modify the scales ( using QwtPlot::setAxisScale ) instead.

Uwe

chinalski
11th February 2013, 20:22
Thank you Uwe,
I will study in deep what you suggest about zooming.

And what about the error messages? The problem seems to me that is not related to zoom, but is about the total dimension of the plot: if the dimension is little everything is okay, if the dimension is bigger I get the errors (same number of samples, just different dimension of the plot).

Searching on the web I found this page:
http://www.developer.nokia.com/Community/Wiki/QPainter::begin:Paint_device_returned_engine_%3D%3 D_0_%28Known_Issue%29
who say: "The solution is pretty simple and it's about defining a valid size for the QPixmap to paint. For instance defining it as QPixmap pix(100, 100) fix this issue."

Since using qwtPlot I have no access to QPixMap, how can I try to solve this?
Thanks

Uwe
12th February 2013, 16:17
You have to disable the backing store of the canvas ( QwtPlotCanvas::BackingStore ).

Uwe