I have a QWidget that I don\'t want to show on screen. Instead I want to get a pixmap of the widget every time it is repainted, in order to send it to another part of the ap
As another way - you can do next check:
void paintEvent(QPaintEvent*)
{
QPainter painter(this);
// If painter redirection was turned on, the painter will *not* paint on `this`!
// Painting code
//...
if ( this == qobject_cast< QWidget * >( painter.device() ) )
{
// Do grabbing
}
}
paintEvent is called both for painting on widget and on grabbing. painter->device()
will return not null, but instance of QWidget *
object only when current painting is on widget. In case of drawing on QPixmap
- it will return QPixmap *
. So you need to call grabbing code only when painting is performed only on real widget.