Qt 小部件稍后更新,但什么时候更新?
我想知道当我调用 QWidget 的 update() 方法时到底会发生什么。
这是文档:
http://doc.qt.digia.com/4.5 /qwidget.html#update
该函数不会导致 立即重新喷漆;相反它 安排绘制事件进行处理 当Qt回到主赛事时 环形。这允许 Qt 优化 比a更快的速度和更少的闪烁 调用 repaint() 即可。
我从 Qt 源代码中看到创建了 QUpdateLaterEvent 并以 QEvent::UpdateLater 类型发布
在文档的这一部分中 http://doc.qt.digia.com/4.5/qevent.html
QEvent::UpdateLater:小部件 应该排队重新喷漆 稍后再说。
“稍后”是什么意思?
我的所有发出的排队信号和事件队列中的事件是否在绘制之前得到处理?
谢谢,
加博尔
I'd like to know what happens exactly when I call a QWidget's update() method.
Here is the documentation:
http://doc.qt.digia.com/4.5/qwidget.html#update
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.
I see from the Qt source code that a QUpdateLaterEvent is created and post with type QEvent::UpdateLater
In this part of the documentation
http://doc.qt.digia.com/4.5/qevent.html
QEvent::UpdateLater: The widget
should be queued to be repainted at a
later time.
What does 'later time' mean?
Are my all emited queued signals and the events in the event queue processed before the paint?
Thanks,
Gabor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查 QWidget::update() 源代码后,我发现它在
src/gui/kernel/qwidget.cpp:9544
中调用此方法:如您所见
QUpdateLaterEvent
仅当 update() 已从 PaintEvent() 方法内部调用时才会发布。您还可以检查第 9456 行上的
QWidget::repaint(const QRect &rect)
源代码 - 它缺少testAttribute(Qt::WA_WState_InPaintEvent)
检查。编辑
QUpdateLaterEvent
作为Qt::NormalEventPriority
事件发布,因此它在所有其他正常优先级事件之后得到处理(请参阅src /corelib/kernel/qcoreapplication.cpp:971
和:1003
)。您可能还想查看 compressEvent 代码,我还没有检查过。最后回答这个问题:QUpdateLaterEvent 在发布之前队列中的其他高优先级和普通优先级事件之后进行处理。
After checking QWidget::update() source code I've found it calls this method in
src/gui/kernel/qwidget.cpp:9544
:As you can see the
QUpdateLaterEvent
is only posted if the update() is already called from inside a paintEvent() method.You can also check
QWidget::repaint(const QRect &rect)
source on line 9456 - it lackstestAttribute(Qt::WA_WState_InPaintEvent)
check.EDIT
The
QUpdateLaterEvent
is posted as aQt::NormalEventPriority
event, so it gets processed after all other normal priority events (seesrc/corelib/kernel/qcoreapplication.cpp:971
and:1003
). You might also want to look into compressEvent code, I haven't checked that.So to finally answer the question: the QUpdateLaterEvent is processed after other high and normal priority events that were in queue before it was posted.
行为未记录 == 不保证 Qt 版本之间保持相同。您不应编写依赖于绘制事件相对于其他事件的顺序的代码。
Behavior is not documented == not guaranteed to stay the same between Qt versions. You shouldn't write code which depends on the ordering of paint events relative to other events.