Qt painting without clearing the background

妖精的绣舞 提交于 2019-12-10 14:43:06

问题


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


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1644514/qt-painting-without-clearing-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!