Reputation:
I'm using Qt and I want my program to be able to go in the system tray, but also to be displayed as a window.
For example: I launch my program, it opens a window, ..., I close the window but the program doesn't close, it is still in the background. Then I can reopen the window through the icon created in the system tray.
I know how to create the icon using QSystemTrayIcon and to create a menu when right-clicking on the icon, and launch events through the menu. Yet I don't know how to do so that when I close my program's window, the program remains opened in the background.
To illustrate my point, it would be the same functionment as Steam.
Upvotes: 5
Views: 2499
Reputation: 16324
You need to reimplement QWidget::closeEvent
, hide the window and ignore the QCloseEvent
.
This is explained in detail in the Qt System Tray Icon Example, here is the most interesting part:
void Window::closeEvent(QCloseEvent *event)
{
if (trayIcon->isVisible()) {
hide();
event->ignore();
}
}
Upvotes: 5