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

zeljko zeljko at holobit.net
Mon May 18 14:03:40 CEST 2009


On Monday 18 May 2009 11:18, Paul Ishenin wrote:
> 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.

Docs says a big warning about usage of QPixmap:grabWidget() inside paintEvent 
(so it's not useable).

It is possible that this way can do the trick (cannot test at the moment)
QPainter_end(Painter);
QPixmap_grabWidget(Widget);
QPainter_begin(Painter);


There's also QPixmap_grabWindow() but that one doesn't grab widget but screen 
area from given parameters.

zeljko





More information about the Qt mailing list