Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt painting without clearing the background

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

like image 313
viraptor Avatar asked Oct 29 '09 15:10

viraptor


3 Answers

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.

like image 72
hochl Avatar answered Oct 29 '22 22:10

hochl


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

like image 35
Patrice Bernassola Avatar answered Oct 29 '22 22:10

Patrice Bernassola


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.

like image 34
Frerich Raabe Avatar answered Oct 29 '22 22:10

Frerich Raabe