Reputation: 29
I have some problems. Hope anyone can help me. I have a Qwidget1 and Qwidget2. Qwidget1 have a widget that promote to Qwidget2. Both Qwidget1 and Qwidget2 have paintEvent. I have writed "qDebug()<< "Update"; " in paint event of Qwidget1. When I run project, I see a word "Update" has been printed a lot of times. So why Qwidget1 execute paint event a lot of times. How can I fix it, just execute paint event when show Qwidget1 at the first time and when I call update.
Upvotes: 1
Views: 769
Reputation: 33579
There can be any number of situations when a window or its part becomes invalidated and has to be repainted. Such situations include, but are not limited to:
When it happens, Windows will send the WM_PAINT
message to the application. You could check whether or not the number of WM_PAINT
messages received matches the number of paintEvent
calls, but I doubt Qt adds any significant overhead.
Upvotes: 1
Reputation: 4010
This is expected behavior. Your code works like it should. From Qt documentation:
A paint event is a request to repaint all or part of a widget. It can happen for one of the following reasons:
repaint() or update() was invoked,
the widget was obscured and has now been uncovered,
or many other reasons.
Upvotes: 1