PDA

View Full Version : Painting into QPixmap



jessiemmichael
8th September 2009, 04:45
The task is to display the image with list of overlays(rectangle or circle) and store them into a file.

The current implementation is,
1) We use custom widget that is derived from QWidget that paints the image and its overlays. All the implementation is in painter event.
2) We store the content with grabWidget.


Now we want to change the logic,

We have introduced worker thread where in storing the images can be implemented. Can I use QPixmap as painter device in worker thread?

yogeshgokul
8th September 2009, 05:10
Can I use QPixmap as painter device in worker thread?
Yes :)
The QPixmap class is an off-screen image representation that can be used as a paint device.

jessiemmichael
8th September 2009, 05:47
I noticed in one the replies of Wysota's for " real time data display" that having reference to QPixmap in worker thread is not safe.

I guess it is not possible to manipulate image and overlays into Qpixmap object in worker thread.

yogeshgokul
8th September 2009, 06:07
Thats true, in that case you can use painting on QImage.

From Qt Docs:

Painting in Threads:
QPainter can be used to paint onto QImage, QPrinter, and QPicture paint devices. Painting onto QPixmaps and QWidgets is not supported. On Mac OS X the automatic progress dialog will not be displayed if you are printing from outside the GUI thread.

More Info here (http://doc.trolltech.com/4.5/threads.html#painting-in-threads).

wysota
8th September 2009, 09:08
Yes :)
The QPixmap class is an off-screen image representation that can be used as a paint device.

No. QPixmap is an on-server image representation that can't be used from worker threads. QImage can.

yogeshgokul
8th September 2009, 09:12
No. QPixmap is an on-server image representation that can't be used from worker threads. QImage can.

Yeah, I know, just got confused with the meaning of worker thread, I knew this phrase as NON-GUI thread. But now I will also call it same. ;)

I already accepted that and proposed same.

Thats true, in that case you can use painting on QImage.