Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / qt / 2009-05

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

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

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.
zeljko
to Paul Ishenin
Paul Ishenin wrote 19 lines
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

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

Yes, I know. It leads to endless loop: grabWidget_() -> paintEvent() -> grabWidget -> ...

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

It will be the same endless loop.

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

I have tried it but as I wrote it paints garbage instead of widget backgound.

Best regards,
Paul Ishenin.

Den Jean
to Paul Ishenin: Hello, Items specific to the Qt widget set. Imagine a situation we have a TForm canvas…
Paul Ishenin wrote
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:

reading material:
http://doc.trolltech.com/qq/qq16-background.html
http://doc.trolltech.com/4.1/qwidget.html#transparency-and-double-buffering http://doc.trolltech.com/qq/qq16-fader.html

in the fader example you could copy content of underlying widget and do your transformation.
Qwidget properties should be set for event transparency (Qt::WA_TransparentForMouseEvents)
(never tried this)

regards,

Den Jean