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 );
}