PDA

View Full Version : QPainter reuse within a paintEvent



Micawber
2nd May 2008, 16:06
Is it possible/wise to re-use a QPainter within the paintEvent message? Something like...


MyWidget::paintEvent( QPaintEvent *event )
{

QPainter painter;

painter.begin( m_pixmap );
painter.initFrom( this );
painter.some_painting_stuff();
painter.end();

painter.begin( this );
painter.initFrom( this );
painter.some_painting_stuff();
painter.end();
}

aamer4yu
2nd May 2008, 16:27
And why cant u use it like -


MyWidget::paintEvent( QPaintEvent *event )
{
QPainter painter(this);
painter.drawPixmap(,,,,,,);
painter.some_painting_stuff1();
painter.some_painting_stuff2();
}

Is there some problem or restriction in doing so ??

Micawber
2nd May 2008, 16:51
Because for some odd reason, I had it in my head to create the pixmap within the paintEvent, then display it with the new painter(this) painting on the widget. Of course I have code that detects when the pixmap needs to be redrawn. 99% of the time it doesn't need to be redrawn so it should just copy the previous one onto the widget.

I was having some weird problems and I wanted to know if what I was doing was ok.

I have since changed the code around to generate the pixmap in a separate method and have had better results so obviously what I was doing was causing the weird problem. I just wanted to know why? :confused: