repaint与update的区别

编程知识 更新时间:2023-05-02 19:05:04

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的区别

本文发布于:2023-04-28 04:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/fd928e3258628ff95b9927c13ee980ef.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   repaint   update

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107656文章数
  • 27232阅读数
  • 0评论数