[Qt] How to copy QWidget content into QPixmap/QImage inside that QWidget paintEvent() ?

Paul Ishenin ip at kmiac.ru
Mon May 18 11:18:20 CEST 2009


Hello,  Items specific to the Qt widget set.

Imagine a situation we have a TForm canvas and we want to copy its 
content to the TBitmap canvas, then do some manipulations with TBitmap 
canvas and draw it back to the TForm canvas (example is here: 
http://bugs.freepascal.org/view.php?id=12131).

To do so we need to copy from QPainter/QWidget to QPixmap/QImage first 
(form.Canvas -> bitmap.Canvas). But we can't do so inside TForm.OnPaint 
handler (QWidget.paintEvent) using known to me methods:
a) QPixmap::grabWidget()
b) QWidget::render()

We can use QPixmap::grabWindow() but I get only some garbage instead of 
widget background.

Maybe someone know another way? I don't believe that it is imposible to 
copy already drawn part of widget into pixmap/image inside that widget 
paintEvent(). But on the other hand I can't find how to do so.

Please help.

--
Best regards,
Paul Ishenin.





More information about the Qt mailing list