Reputation: 79477
I have a Qt app which, like Skype, is usually minimized to the tray. When the user clicks the tray icon, the app window is shown.
This works fine on Linux and WinXP. On Win7 however, the app window is shown but stays below the other windows - unless the currently active window is Qt Creator, or was my app (before I minimized it to tray). So it must have something to do with focus stealing prevention.
I know Skype is written in Qt, and they don't have that problem, so it must be fixable.
Here's my code:
void MainWindow::toggleVisible(QSystemTrayIcon::ActivationReason reason) { if (QSystemTrayIcon::Trigger == reason) setVisible(!isVisible()); }
[Edit] It turns out I had to call activateWindow. I changed my code to:
void MainWindow::toggleVisible(QSystemTrayIcon::ActivationReason reason) { if (QSystemTrayIcon::Trigger == reason) { if (isVisible()) { hide(); } else { show(); raise(); activateWindow(); } } }
It works on Win7 now.
Upvotes: 2
Views: 1001
Reputation: 47602
I use the following code to make my application visible when clicked from tray;
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
this will handle the case its in minimized and you click the tray icon.
Upvotes: 1