Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Leo Chapiro 14-Jan-16 5:52am    
You'll receive paintEvent every time when the operating system needs you to repaint your window. And you can't "fix" it! What do you want to achieve?
LeHuuTien 14-Jan-16 6:20am    
I want execute paint event when show Qwidget1 at the first time and when I call update.

1 solution

From the QWidget::paintEvent[^] documentation:
Quote:
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.


So there may be many reasons why the widget (or portions of it) must be repainted (among the not mentioned ones above are resizing and moving of the window). If you are sure that this is not sourced by your code (e.g. by calling the widget's repaint() function instead of the update() function or perfoming other tasks that might trigger the paint event) you will have to live with the behaviour.

If you have performance issues, you should optimise your paint implementation (e.g. by updating only those portions that are covered by the passed region / rect).

If you really want to know what might be the cause of the events, you should also check the region / rect to see if only portions or the complete widget has to be updated and dig deep into the Qt sources.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900