repaint與update的區別

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()。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章