repaint会立刻调用paintEvent重绘,而update是把绘制事件加入主事件循环。
Qt文档:
[slot] void QWidget::repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.
We suggest only using repaint() if you need an immediate repaint, for example during animation. In almost all circumstances update() is better, as it permits Qt to optimize for speed and minimize flicker.
Warning: If you call repaint() in a function which may itself be called from paintEvent(), you may get infinite recursion. The update() function never causes recursion.
会立刻调用paintEvent()函数来进行重绘,除非这时候不可以update或控件是隐藏的。
建议只有当需要立刻重绘的时候调用repaint,比如在动画过程中使用。多数情况下update()是更好的选择,因为它可以让Qt进行优化从而实现更少及更快的闪烁。
如果在一个函数里面调用了repaint,而这个函数可能会被paintEvent()调用,可能会引起无限递归。但update()绝不会引发无限递归。
[slot] void QWidget::update()
Updates the widget unless updates are disabled or the widget is hidden.
This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop. This permits Qt to optimize for more speed and less flicker than a call to repaint() does.
Calling update() several times normally results in just one paintEvent() call.
Qt normally erases the widget's area before the paintEvent() call. If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is responsible for painting all its pixels with an opaque color.
更新控件,除非这时候不可以update或控件是隐藏的。
不会立刻重绘。它会加入一个绘制事件,当Qt返回主事件循环的时候处理。相比repaint(),能让Qt进行优化从而实现更少及更快的闪烁。
调用多次的update()通常只会调用一次paintEvent()。
更多推荐
repaint与update的区别
发布评论