PDA

View Full Version : QPainter above already painted



^NyAw^
26th February 2014, 15:02
Hi,

I'm trying to use QPainter inside a QGLWidget to draw images and rectangles, circles, ... using OpenGL backend.

First I display an image using a QPainter and painting a QPixmap.
Then I paint a rectangle using a QPainter and painting it.

The problem is that the second painting clears the image(normal behaviour as I can read).

I can't store the image to repaint it adding the other elements so I want to keep the already painted elements to not be cleared.

Is there anyway to paint above what is already painted?

From Qt doc, it says that QPainter can only be used inside the paintEvent when the PaintDevice is a Widget(this is the case), but I'm using it outside the paintEvent without problem.

Thanks,

anda_skoa
26th February 2014, 19:59
From Qt doc, it says that QPainter can only be used inside the paintEvent when the PaintDevice is a Widget(this is the case), but I'm using it outside the paintEvent without problem.

That just refers to painting on a widget. The only place you can paint on a widget is in its paintEvent() method. You can use QPainter on any other QPaintDevice whenever you want as long as there are no other restrictions on the given paint device. E.g. you can only paint on a QPixmap from within the main/GUI thread.

Cheers,
_