PDA

View Full Version : How to restrict setWindowState() for left-click on QSystemTrayIcon



rawfool
5th April 2013, 08:40
I invoke a SLOT on click of QSystemTrayIcon activated SIGNAL. The slot does - setWindowState(Qt::WindowActive).
Now I've added context menu which is appearing on right-click of tray-icon. But the Window is also showing on right-click of tray-icon. How do I restrict the setWindowState to be active only on left-click of the tray-icon ?
Thank you.

Infinity
7th April 2013, 00:26
Just set the context menu using the "setContextMenu"-method of the QSystemTrayIcon.
The activated signal is also emitted when the context menu is requested, so you have to check the activation reason before setting the window state.



void MainWindow::trayIconActivated(QSystemTrayIcon::Act ivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
setWindowState(Qt::WindowActive);
break;
default:
;
}
}