PDA

View Full Version : Drawing on QPixmap fails / How to convert QPitcure to QPixmap



RThaden
27th August 2008, 19:24
Hi all,

i need to draw a pixmap on a widget which consists about 6 or 7 images.
When I draw directly on the widget in paintEvent, everything is fine.
Now, I want to draw the pixmap once and save it, then, just put it on the widget in paintEvent. However, this does not work correctly.
A snippet of code follows:


QPainter painter(&pixmap);
painter.drawPixmap(3, 3, pixmapBG);
// and some more commands
painter.end(); // painting done

pixmap is a member of my class.

This gives me a message:
QPainter::begin: Paint device returned engine == 0, type: 2

When I use a QPicture instead, it works. QImage also doesn't work.
I don't understand why.
I could use a QPicture for painting and replay it everytime, however, the performance is poor.
Is it possible to convert QPicture to QPixmap? I didn't find anything about that.
I could use play, but then I need to use QPainter painter(&pixmap) again which doesn't work for me. :confused:

I use Qt 4.4.0 on WindowsXP and Vista.

Thanks for any hint.

Regards,

Rainer

aamer4yu
27th August 2008, 19:34
Did u use QPainter::begin ??

jacek
27th August 2008, 19:51
How do you create that pixmap? Does it have a size?

RThaden
28th August 2008, 12:55
Thanks for your replies.

1. When you pass the pixmap or picture in the constructor of QPainter, you don't have to use begin, AFAIK.

2. No, it doesn't have a size. It's just


QPixmap pixmap;

Is that relevant?

Best regards,

Rainer

RThaden
28th August 2008, 13:13
Thanks Jacek, it was the size.
I just tested

QPixmap pixmap(600,400);
QPainter(&pixmap);

and that works.