Update and repaint of QT repainting

Source: Internet
Author: User

Update and repaint of QT repainting

 

 

 

The repainting in QT is similar to that in Windows programming. However, QT re-painting is more distinctive and intelligent.

 

Before speaking, let's talk about paintevent ()

Paintevent () is a virtual function slot. sub-classes can override the paintevent of the parent class. When Update () and repaint () are called, paintevent () is called. In addition, when the interface changes, paintevent () is also called, this kind of interface changes include the interface size changes from hiding to display, and of course the interface content changes will be called. Paintevent () is a highly optimized function. It has automatically enabled and implemented dual buffering (the X11 system needs to manually enable dual buffering ), therefore, re-painting in QT will not cause any flashes.

The method to manually enable dual-buffering for X11 systems is as follows:

... <Br/> extern void qt_x11_set_global_double_buffer (bool); <br/> qt_x11_set_global_double_buffer (false); <br/>...

 

 

With paintevent knowledge, let's take a look at Update () and repaint ()

Update and repaint are the same type. The re-painting object needs to be called and re-painted. After update and repaint are called, both go back to call paintevent ().

 

 

Repaint () is called and re-painted immediately. Therefore, repaint is the fastest. repaint () can be used to re-paint immediately in an emergency (). However, the repaint function cannot be called in paintevent. For example, a sub-class mywidget that inherits from qwidget and overwrites paintevent in the sub-class. We call repaint () in mywidget: myrepaint (). However, myrepaint () is also called by the rewritten paintevent. In this way, the function that calls repaint () is called by paintevent (). Because repaint () is re-painted immediately, and repaint () does not perform any optimization operations until paintevent is called, instead, it will cause an endless loop, that is, calling repaint () first, then calling paintevent (), and paintevent () in turn calling repaint ()... such an endless loop.

 

Compared with repaint (), update is more advantageous. After Update () is called, the re-painting event is not immediately repainted. Instead, the re-painting event is put into the main message loop, which is uniformly scheduled by the main event loop (which is actually relatively fast ). Update has made many optimizations before calling paintevent. If update is called many times, these updates will be merged into a large redrawing event and added to the message queue, at last, only this large update is executed once. It also avoids the endless loop mentioned in repaint. Therefore, in general, it is enough to call update. Compared with repaint (), update is recommended.

 

 

 

Copyright statement:
Reprinted Article please indicate the original source http://blog.csdn.net/feiyinzilgd/archive/2011/01/04/6116634.aspx

Contact tan Haiyan or go to tan Haiyan's personal homepage to leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.