When to call the update() on widgets?
When does the update() method needs to be called?
Do I have t开发者_如何学Goo call it at all?
All I am doing with my widgets are setGeometry() and raise().
setGeometry()
and raise()
should automatically cause a paintEvent
on the corresponding widgets.
I think most of Qt's own widgets call update()
where appropriate. On custom widgets you call update()
whenever something that is visible changes. For example, if you have your own Label class (that does not inherit from QLabel
and hence does not use QLabel
's facilities to change text and/or image), you call update()
whenever you change the content, such that the new content will be displayed on screen.
Beware: You should not use repaint()
on widgets if the repainting is not really time critical. repaint()
causes a paintEvent
to be issued to the widget at the moment it is called, whereas update()
just queues a paintEvent
to be issued the next time the process reaches the main loop. This allows the paint engine to collect several paintEvent
s for the same widget and issue just one combined event. Using repaint()
can thus really impact performance.
精彩评论