Hide the QT window after Minimization

Source: Internet
Author: User
Hide the minimized window

A button is usually displayed on the taskbar in the minimized window. Click this button to restore the window. This is a universal design used by most desktop environments, such as Windows, Kde, and gnome. However, because the taskbar is usually only a small line on the desktop side, it cannot hold a lot of buttons, users usually want to hide those less commonly used programs, only display a small icon in the notification bar, click the small icon to restore the window. The most typical examples are QQ and Winamp.

I thought this function was very easy. I tried it today and it was still a little troublesome. The most basic idea is to intercept the minimum event of the window. by reading the QT document, you can do this:

Void mywindow: changeevent (qevent * event)

{

If (Event-> type () = qevent: windowstatechange)

{

If (windowstate () & QT: windowminimized)

{

Hide ();

Msystemtrayicon-> show ();

}

Qmainwindow: changeevent (event );

}

Take this code and try it. If no result is displayed, the buttons on the taskbar are still there. After you click Restore, the window is blank. Think twice, probably because the changeevent () is called before QT processes the minimal event. We hidden the window, but QT thought the window was about to be minimized. Run the code to process the minimized window again. So an error occurred.

The solution is to minimize the processing window of QT and hide the window after processing. In this case, rewrite the line of hide ():

Qtimer: singleshot (0, this, slot (hide ()));

This is a special use of singleshot (). If the first parameter, that is, the waiting time is 0, when QT returns to the message loop, generally, this is to run this-> hide () immediately after the currently processed event is processed ();

To click the processing code of the notification bar icon, you need to add setwindowstate ():

Mywindow: showme ()

{

Show ();

Setwindowstate (QT: windownostate );

}

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.