How to restrict setWindowState() for left-click on QSystemTrayIcon
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.
Re: How to restrict setWindowState() for left-click on QSystemTrayIcon
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.
Code:
void MainWindow
::trayIconActivated(QSystemTrayIcon::ActivationReason reason
) {
switch (reason)
{
setWindowState(Qt::WindowActive);
break;
default:
;
}
}