Hi!
I've been trying to make any mouse click to open the Tray Icon Menu in a C++ QApplication.
The left mouse click show the menu by it's default behavior and I want exactly the same for when I right mouse click.
The best I could achieve is to add the 'activated' event to the trayIcon object like this
connect(trayIcon, &QSystemTrayIcon::activated, this, &BtManTray::trayIconActivated);
then I've this
void BtManTray::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::ActivationReason::Trigger:
trayIconMenu->popup(QCursor:
os());
break;
default:
;
}
}
This seem to work but it's not the same as opening the context menu.
It's practically drawing a new one in the mouse position.
Also the Window Manager Theme and Icon Theme is not applied to this new menu.
I was able to force the Icon Theme to Papirus Dark (the same OS icon theme) but I prefer that to be inherited from the OS just like the default context menu.
Default context menu
The right click activated event menu
As you can see it's not the same menu regarding position and style.
I already try to use
trayIconMenu->show();
but it shows in top left corner of the desktop and it also lose themes.
This is a XFCE DE maybe I should use GTK instead of Qt.
The default menu seems to be handled by the system and that's why it inherited the styles and the right click is handled by the Qt App.
It must be something related to that.
So I think I should find a way to send an event to the system when I right click that opens the context menu.
I can't find a solution to this.
I've been trying to make any mouse click to open the Tray Icon Menu in a C++ QApplication.
The left mouse click show the menu by it's default behavior and I want exactly the same for when I right mouse click.
The best I could achieve is to add the 'activated' event to the trayIcon object like this
connect(trayIcon, &QSystemTrayIcon::activated, this, &BtManTray::trayIconActivated);
then I've this
void BtManTray::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::ActivationReason::Trigger:
trayIconMenu->popup(QCursor:

break;
default:
;
}
}
This seem to work but it's not the same as opening the context menu.
It's practically drawing a new one in the mouse position.
Also the Window Manager Theme and Icon Theme is not applied to this new menu.
I was able to force the Icon Theme to Papirus Dark (the same OS icon theme) but I prefer that to be inherited from the OS just like the default context menu.
Default context menu
The right click activated event menu
As you can see it's not the same menu regarding position and style.
I already try to use
trayIconMenu->show();
but it shows in top left corner of the desktop and it also lose themes.
This is a XFCE DE maybe I should use GTK instead of Qt.
The default menu seems to be handled by the system and that's why it inherited the styles and the right click is handled by the Qt App.
It must be something related to that.
So I think I should find a way to send an event to the system when I right click that opens the context menu.
I can't find a solution to this.