0

Background

I'm developing an application in PyQt5 which uses the system tray. I've tried the application on LXDE where left clicking on the systray icon shows the menu (right click is handled by LXDE). My friend who runs XFCE has now also tried the application but for him the nothing happens when left clicking the systray icon, to see the menu he has to right click instead

Question

How can I get left click on the system tray in XFCE icon to show the systray menu?

Setup

Qt version: 5.7.1

Code

tray_icon = QtWidgets.QSystemTrayIcon(
    QtGui.QIcon(mc_global.get_app_icon_path()),
    self.matc_qapplication
)
tray_icon.show()
tray_menu = QtWidgets.QMenu(main_window)

# adding menu entries

tray_icon.setContextMenu(tray_menu)
sunyata
  • 1,843
  • 5
  • 27
  • 41

2 Answers2

0

XFCE is based on GTK2, and its tray is not capable to handle left mouse click. A workaround is to install a package sni-qt that adds additional menu entry "Activate" for right mouse click. After installing this package you have to create a config file $HOME/.config/sni-qt.conf containing the following:

[need-activate-action]
myapp=1

where myapp is your application name.

Michael
  • 5,095
  • 2
  • 13
  • 35
  • sir sorry I'm comment here,this comment regarding https://stackoverflow.com/questions/46813590/how-can-i-select-the-qgraphicview-item-and-change-the-size this question,please help me sir if you can,your previous answer is deleted and I haven't any other option to contact you,that s why I'm comment here,so please help me,thank you – Rooter Oct 19 '17 at 09:34
0

It's possible to use the activated signal like this:

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        # ...
        self.tray_icon = QtWidgets.QSystemTrayIcon(QtGui.QIcon("icon.png"), self)
        self.tray_icon.activated.connect(self.on_systray_activated)
        # ...
    def on_systray_activated(self, i_activation_reason):
        # ...

This works on XFCE 4.12

Documentation:

sunyata
  • 1,843
  • 5
  • 27
  • 41
  • I thought this solution was good, but it turns out that it causes problems (gives `Abort trap: 6`) on MacOS for the line `self.tray_icon.activated.connect(self.on_systray_activated)` so i can't recommend it – sunyata Dec 26 '17 at 21:52