• 8201阅读
  • 7回复

[讨论]关于QWidget::repaint()的一个小问题 [复制链接]

上一主题 下一主题
离线zooood
 
只看楼主 倒序阅读 楼主  发表于: 2011-03-09
各位大大,我记得qt2.2.0里面repaint()函数的相关重载函数都有个ERASE参数
是布尔型,true代表预擦除,false代表不会预擦除

可是接触到qt4后,发现这个参数没了,请问这个功能现在用什么机制来代替了?

附qt2的截图
[ 此帖被zooood在2011-03-09 14:24重新编辑 ]
离线zooood
只看该作者 1楼 发表于: 2011-03-09
自顶~~~~~~~~~
离线zooood
只看该作者 2楼 发表于: 2011-03-10
再顶!!!!!
离线luoyang

只看该作者 3楼 发表于: 2011-03-10
再顶
离线coblan

只看该作者 4楼 发表于: 2011-03-11
Re:获取QT窗口句柄
painter与 paint device 相关联时,painter.begin() 是自动调用的,当调用时,缺省将会自动擦除背景。。
你可以设置 setAutoFillBackground();来不让他自动擦除。。。
同样,双缓冲机制也是在 painter.end()时,自动执行。你也可以设置关闭,然后自己来swapbuff


[ 此帖被coblan在2011-03-11 11:00重新编辑 ]
离线zooood
只看该作者 5楼 发表于: 2011-03-11
终于等到解答了呀,眼泪哗哗流啊,怕理解错了去查了下,就是这个参数了吧:
autoFillBackground : bool
大致明白意思,不过对“Warning”那段有点费解。它说:如果用了style sheet这个属性就不可用(disabled)
啥叫”不可用“呢,是不是用了style sheet就会始终自动刷新背景,而不管autoFillBackground是true还是false?

E文原文(重点是红的那段):
This property holds whether the widget background is filled automatically.

If enabled, this will cause Qt to fill the background of the widget before invoking the paint event. The color used is defined by the QPalette::Window color role from the widget's palette.

In addition, Windows are always filled with QPalette::Window, unless the WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set.

Warning: Use this property with caution in conjunction with Qt Style Sheets. When a widget has a style sheet with a valid background or a border-image, this property is automatically disabled.

By default, this property is false.

This property was introduced in Qt 4.1.
[ 此帖被zooood在2011-03-11 16:04重新编辑 ]
离线coblan

只看该作者 6楼 发表于: 2011-03-12
Re:获取QT窗口句柄
这真是个麻烦事,不管怎么弄,背景还是会被重绘。本来很简单的东西,文档也没说清楚它是怎么弄的。。
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重新编辑 ]
离线zooood
只看该作者 7楼 发表于: 2011-03-19
这个问题蛋疼了好几个月了
快速回复
限100 字节
 
上一个 下一个