PDA

View Full Version : Get backgorund as pixmap



Abnormalia
13th October 2007, 22:15
I disabled drawing for dialog backgound and on paintEvent OpenGL renders something on whole background.

Is it possible to get this "paint" as data pixmap in application then change if and repaing background. if yes how (esp getting background as pixma)? I could not find method in docs to do that.

Thanks all in advance.

marcel
13th October 2007, 22:22
See QPainter::setRedirected().
It is better to add a QWidget on the dialog and treat this as "background".

Then:


QPainter::setRedirected(backWidget, &thePixmap);


Now all painting is done on the pixmap.

jpn
13th October 2007, 22:27
QWidget::render() (introduced in Qt 4.3) might also be handy..

Abnormalia
13th October 2007, 23:21
I tryed like that:

...
QRect ur = e->rect();

QPixmap bgrWidget(ur.width(), ur.height());

QPainter::setRedirected(this, &bgrWidget);

//OpenGL renderer draws something here on background

QImage* m_image = &bgrWidget.toImage();

...

QPainter::restoreRedirected(this);

QPainter painter(this);

painter.begin(this);
painter.drawImage(0,0,*m_image);
painter.end();

....

1 - OpenGL still draw on background.
2 - when second draw occurs it's cmpletelly white and everyhting flickers.

What I'm doing wrong here ?