The event for a state change( e.g. minimize) is QWindowStateChangeEvent.
So I think that your mistake is to call hide() for a hide event. Well, a call to hide() triggered that event in the first place.
So you should handle this event instead,, and hide it there. Also you should ignore the event in this case, because you don't actually want to minimize the window. You just want to use the minimize button for hiding the window.
Please refer to the System Tray example in the Qt Demos for a full example.
Here's a small snippet:
{
if (trayIcon->isVisible()) {
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
hide();
event->ignore();
}
}
void Window::closeEvent(QCloseEvent *event)
{
if (trayIcon->isVisible()) {
QMessageBox::information(this, tr("Systray"),
tr("The program will keep running in the "
"system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu "
"of the system tray entry."));
hide();
event->ignore();
}
}
To copy to clipboard, switch view to plain text mode
This is how they implemented it. They hide the task bar button at close. The only difference is that you hide it at minimize, so the implementation should be the same.
Regards.
Bookmarks