I have connected QSystemTrayIcon::ActivationReason to my 'handleClick' slot as below
connect(tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,SLOT(handleClick(QSystemTrayIcon::ActivationReason)));
mywindow::handleClick(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
handleLeftClickOnTray();
break;
case QSystemTrayIcon::MiddleClick:
break;
default:;
}
}
I have another function called 'handleRightClickOnSystemTray()' which should be called when mouse right button clicked over system tray icon. This function creates a QDialog box and display it. How to handle right click mouse events on system tray ?
You can use QSystemTrayIcon::Trigger which will be invoked when you left click. QSystemTrayIcon::DoubleClick will not trigger when a menu is in place.
If that's not working for you, then you have to reimplement bool QSystemTrayIcon::event(QEvent *e) and install an event filter to check which button was pressed.
The new signal and slot syntax is
or the lamba version