这真是个麻烦事,不管怎么弄,背景还是会被重绘。本来很简单的东西,文档也没说清楚它是怎么弄的。。
If enabled, this property will cause Qt to fill the background of the widget before invoking the paint event [1] //这个说是在重绘事件处理之前,就会重新绘制背景。
testAttribute(Qt::WA_StyleSheet)==false(这应该能说明没有 style sheet 被设置)还是不行。
C++ GUI Programming with Qt4(2nd) 这本书的opengl章节的第二个例子的最后一段话,如下:
QPainter's constructor (or QPainter::begin()) automatically calls glClear() unless we called
setAutoFillBackground(false) on the widget beforehand 。[2]
QPainter's destructor (or QPainter::end()) automatically calls QGLWidget::swapBuffers() to
swap the visible buffer and the off-screen buffer unless we call setAutoBufferSwap(false) on the
widget beforehand.
//这里说的QGLwidget,它是widget的子类,至于Qwidget,又是怎么样,反正实验过了,不管怎么样,背景都会被擦除。。
这里结合[1][2]的说法不知道是否是指重复的擦除背景了,所以还是没弄明白AutoFillBackground,这个属性是针对 paintEvent外的擦除背景,还是针对painter::begin()函数的擦除背景,或者都不是。
////////不过这个功能应该不怎么会用到,如果用到不需要擦除背景的,还是用图片来代替吧,但是期望哪位熟悉QT的朋友帮我们解答一下这个背景擦除的问题。
[ 此帖被coblan在2011-03-12 19:18重新编辑 ]