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.

Qt Code:
  1. // QWidget* widget is the widget whose background we are insterested of
  2.  
  3. // map widget's rect to it's window
  4. QRect bgRect = widget->rect();
  5. bgRect.moveTo(widget->mapTo(widget->window(), bgRect.topLeft()));
  6.  
  7. // need a better solution for this to avoid flickering
  8. widget->hide();
  9. QImage behind = QPixmap::grabWidget(widget->window(), bgRect).toImage();
  10. 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?