I'm doing some effects to a child widget. For performing these effects, I need to grab an image of the child widget's background. Or more correctly, grab an image of anything behind the child widget.
The problem is, that when I call QPixmap::grabWidget() for the widget's parent or window, the widget itself gets naturally drawn too. The only way I have found to avoid this is to hide the widget during the grab. This leads to a slight flickering, which is not what I want.
// QWidget* widget is the widget whose background we are insterested of
// map widget's rect to it's window
QRect bgRect
= widget
->rect
();
bgRect.moveTo(widget->mapTo(widget->window(), bgRect.topLeft()));
// need a better solution for this to avoid flickering
widget->hide();
QImage behind
= QPixmap::grabWidget(widget
->window
(), bgRect
).
toImage();
widget->show();
// QWidget* widget is the widget whose background we are insterested of
// map widget's rect to it's window
QRect bgRect = widget->rect();
bgRect.moveTo(widget->mapTo(widget->window(), bgRect.topLeft()));
// need a better solution for this to avoid flickering
widget->hide();
QImage behind = QPixmap::grabWidget(widget->window(), bgRect).toImage();
widget->show();
To copy to clipboard, switch view to plain text mode
Any ideas, how to achieve the same without the hide/show trick, if it's even possible?
Bookmarks