Qt painting without clearing the background
Asked Answered
S

3

5

I'm using a QPainter to get some graphics on a window. Unfortunately every time the paintEvent() function is called, the whole window is cleared. How can I draw without clearing? I.e. how do I leave the stuff from previous paint event untouched?

I'm using Qt4

Saltzman answered 29/10, 2009 at 15:24 Comment(1)
Which Qt version are you using?Albanian
T
4

You need to set the backgroundMode by using the setBackgroundMode setter. The Qt::NoBackground enum is what you are searching for.

Terryn answered 29/10, 2009 at 15:44 Comment(0)
F
5

Since both replies are for Qt3 only, here is the solution for Qt4. You need to call

setAttribute(Qt::WA_OpaquePaintEvent);

(for example in the constructor) following the documentation here.

Fahland answered 9/8, 2013 at 11:37 Comment(0)
T
4

You need to set the backgroundMode by using the setBackgroundMode setter. The Qt::NoBackground enum is what you are searching for.

Terryn answered 29/10, 2009 at 15:44 Comment(0)
A
1

In Qt3, set the Qt::WNoAutoErase flag from the WidgetFlags enum to avoid that the window is cleared on each paint event.

You can set this flag by passing it to the QWidget constructor.

Albanian answered 29/10, 2009 at 15:30 Comment(2)
Qt Documentation says it no longer needed. So he should not use itTerryn
@Patrice: Ah, yes - in Qt4 it does not work anymore. This is a Qt3 solution.Albanian

© 2022 - 2024 — McMap. All rights reserved.