(turn) A brief talk on the window refresh event in QT

Source: Internet
Author: User

On the window refresh event in QT
[Date: 2011-06-25] Source: Linux Community 袁硕 [Font: Big medium small]
After one weeks of project preliminary development, write this article on the development of some common problems encountered, give some information and their views, hoping to give other beginners or contestants a little help, of course, is also a kind of, we have what good skill experience what, also can share, with the help of this competition, We make progress together ~

If everyone is like me, just beginning to contact QT, began to develop QT program, there will certainly be a lot of unaccustomed places, today I would like to talk about is such an unaccustomed Place--QT window Refresh event.

For the form refresh event, I mainly talk about the use of paintevent, I guess a lot of people may use this for the first time, as I confused, do not understand when this is called, and now let me briefly explain.

void Qwidget::p aintevent (qpaintevent *)

If you do not understand the principle of it, arbitrary find an example of the program you are also difficult to find when it was called traces.

Paint This event is called when the form part needs to be redrawn and is generated by the form system, but when the program is asked to redraw the form part, the event loop selects the event from the event queue and distributes it to the widget that needs repainting. Not all paint events are generated by the windowing system, and you can use it with repaint () or update (). However, you need to know that even if you are impatient and want to call PaintEvent () directly, this is not possible because the PaintEvent () function is protected (probably not accessible). It also bypassed any existing event filters. For these reasons, QT provides a mechanism for directly sending events rather than posting.

However, it is important to note that sometimes update () does not necessarily go directly to paintevent. Why is that? This is because QT automatically merges multiple drawing events into one to speed up the drawing. This, is not also very not used to, but, I think is also very advantageous point, in the implementation of our program, we can put all the drawing form of those statements of the functions of the paintevent, through a variety of such as if-else statements to judge to draw, This is optimized for speed and prevents flicker.

Drawing Events It is also important to note that the update area is usually erased when the drawing event occurs. If you need to draw on the basis of the last drawing, I would like to use a temporary variable to save the last drawing of the diagram, and then to draw on this diagram, and then directly display the graph on the line. is a very stupid way, if you have other better ways to accept the next. By the way, it is possible to know whether the widget is erased by qpaintevent::erased ().
Ps: After the completion of the check, the Wrepaintnoerase window part mark is set when the time will not erase.

void Qwidget::update ()
As mentioned earlier in this event, for updating a form part, it plans the drawing events to be processed. can be optimized by QT, merging multiple drawing events. So it is recommended that you use this instead of repaint (). The result of several calls to update () is usually just a paintevent () call, and this optimization is good for performance.

The introduction of so much today is a basic thing. Daniel do not have to look, hehe, hope and I like the beginners, also can introduce their own development encountered problems, we share the discussion progress.

(turn) A brief talk on the window refresh event in QT

Related Article

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.