PDA

View Full Version : Error while saving large QGraphicsScene as png image using QImage



anwar.qt
4th February 2014, 15:00
Hi,

I have large QGraphicsScene with large number of graphics object on it.
I want to export the scene as image (PNG) it is giving following errors:


Painter::begin: Paint device returned engine == 0, type: 3
QPainter::setRenderHint: Painter must be active to set rendering hints
QPainter::save: Painter not active
QPainter::setClipRect: Painter not active
QPainter::setWorldTransform: Painter not active
QPainter::save: Painter not active
QPainter::setBrushOrigin: Painter not active
QPainter::restore: Unbalanced save/restore
QPainter::opacity: Painter not active
QPainter::worldTransform: Painter not active

CODE:

QImage image(scene->sceneRect().width(), scene->sceneRect().height(), QImage::Format_ARGB4444_Premultiplied);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
scene->render(&painter);
image.save(sFilePath);
But this works fine for the small scene with less no of graphics item on it.
So my queries are-

1. What does it mean by painter not active?
2. How to resolve the above problem?
3. Is it related to scene size and/or no. of graphics items on it?

It would be very helpful for me, if anyone answer the above queries or give any pointers to investigate the issue further.

Thanks!

d_stranz
4th February 2014, 17:39
How large is the sceneRect? If it is too large and QImage cannot allocate enough memory for it, then the QImage will be null (i.e. not a valid paint device), so the painter cannot paint to it.

It does not have anything to do with the number of graphics items in the scene, the problem is the number of pixels in the scene (width x height). You may have to apply a scale transform to the items in the scene to get the scene bounding rect smaller.