How do I make my tray icon display in Ubuntu Budgie in my PyQt5 app?

it seems to just want to read /media with the removable-media plug not connected, that should indeed not be relevant to the icon …

it seems that QSystemTrayIcon actually does not use a Tray Icon at all but uses the appindicator spec under the hood …

perhaps it would help to ship libappindicator1 in your stage packages if you don’t already (and that IIRC also needs the unity7 plug)

I added libappindicator1 to my stage-packages for both of my parts, and I already had unity7 as one of my plugs in testapp under apps in my YAML.

It made no difference regarding the icon on Ubuntu Budgie.

well, it was worth a try at least :slight_smile:

1 Like

another option might be to experiment with QT_QPA_PLATFORMTHEME in an environment entry in your apps: block … i.e. I’d try:

apps:
  ...:
    command: ...
    environment:
      QT_QPA_PLATFORMTHEME: gtk3
    plugs:
      - ...

I changed my environment as follows, and it made no difference.

apps:
    testapp:
        command: bin/desktop-launch python3 $SNAP/main.py &
        plugs:
            - desktop
            - desktop-legacy
            - x11
            - unity7
            - gsettings
        environment:
            DISABLE_WAYLAND: 1
            QT_QPA_PLATFORMTHEME: gtk3

well, that seems to allow other values as well (qt5ct, gtk2, gnome, kde) i’d try them one by one , perhaps they change something in how the icon is rendered/displayed …

1 Like

I couldn’t find a comprehensive list anywhere, but I was able to find a number of hypothetical values from looking at a variety of different Q-A threads like this one across the net. I tried each of these values individually and none made any difference:

QT_QPA_PLATFORMTHEME: gtk3
QT_QPA_PLATFORMTHEME: gtk2
QT_QPA_PLATFORMTHEME: qt5ct
QT_QPA_PLATFORMTHEME: gnome
QT_QPA_PLATFORMTHEME: lxqt
QT_QPA_PLATFORMTHEME: kde

dang, that’s sad … is there any particular reason why you use a gtk desktop launcher for a Qt app btw ?

perhaps you are missing variables the qt variant of the desktop launcher would actually set …

Honestly, I have no idea what I’m doing. I’ve compiled snippets from a bunch of sources and created a product that basically works, without a lot of understanding of how all the pieces fit together. I don’t know what a “desktop launcher” is. Are you saying I can get rid of the whole desktop-gtk part in my YAML? And if I did that, might that help with the icon? Do I need to replace the desktop-gtk part with something else?

I would probably know more about the YAML if re-snapping didn’t take so long, because I’d mess with it more to remove unnecessary stuff. But snapping takes so long that once I get something that works I stop messing with it!

no, i’m saying there is also a qt variant of that same launcher …

remove the gtk launcher part from your snapcraft.yaml and copy in that one instead … and replace the source: entry with:

source: https://github.com/ubuntu/snapcraft-desktop-helpers.git

(and also read the usage info in the description at the top of the file)

1 Like

Here’s my new YAML file, but switching from desktop-gtk to qt5 didn’t fix the tray icon problem.

name: testapp
base: core18
version: '1.0.0'
title: 'TestApp'
summary: 'Just a test app to do tests with'
description: 'Just a test app to do tests with'
grade: stable
confinement: strict

apps:
    testapp:
        command: bin/desktop-launch python3 $SNAP/main.py &
        plugs:
            - desktop
            - desktop-legacy
            - x11
            - unity7
            - gsettings
        environment:
            DISABLE_WAYLAND: 1

parts:
    copy-stuff:
        plugin: dump
        source: .
    qt5:
        source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
        source-subdir: qt
        plugin: make
        make-parameters: ["FLAVOR=qt5"]
        build-packages:
            - qtbase5-dev
            - dpkg-dev
        stage-packages:
            - libxkbcommon0
            - ttf-ubuntu-font-family
            - dmz-cursor-theme
            - light-themes
            - adwaita-icon-theme
            - gnome-themes-standard
            - shared-mime-info
            - libqt5gui5
            - libgdk-pixbuf2.0-0
            - libqt5svg5 # for loading icon themes which are svg
            - try: [appmenu-qt5] # not available on core18
            - locales-all
    testapp:
        plugin: python
        python-version: python3
        source: .
        python-packages:
            - setproctitle
        build-packages:
            - coreutils
            - python3-requests
        stage-packages:
            - coreutils
            - libssl-dev
            - libjpeg-dev
            - libtiff-dev
            - libsdl1.2-dev
            - libnotify-dev
            - freeglut3
            - zlib1g
            - libsm6
            - libpulse0
            - libslang2
            - libsdl1.2debian
            - wmctrl
            - gir1.2-appindicator3-0.1
            - python3-gi
            - gir1.2-wnck-3.0
            - x11-utils
            - python3-requests
            - python3-pyqt5
            - libappindicator1
        requirements:
            - /root/project/requirements.txt

Tray icon issues is with he system that you are using, QSystemTrayIcon works with almost every system tray provider and its cross platform too.

We tested that there is nothing wrong with packaging an app that uses QSystemTrayIcon class inside snap as the systray itself do not show icon of qbittorrent normal install. Raise the issue with the budgie desktop env about the issue do not include snaps, tell them there is no icon in system tray for qbittorrent .deb install or what ever way you tried.

2 Likes

An update, QBitTorrent snap does not show icon here on XFCE desktop environment. But shows an entry, hence there is something wrong with QBittorrent App, as all my apps that uses QSystemTray shows tray icon entry here perfectly.

Maybe some tracks to dig over there https://discourse.ubuntubudgie.org/t/hplip-hplip-toolbox-broken-in-budgie/2749/26?u=coeur-noir Qt and (Ubuntu)Budgie are sometimes surprising…

I don’t know the state of the art upstream : https://discuss.getsol.us/ or https://github.com/solus-project/budgie-desktop/issues

Last time I used Ubuntu Budgie, it used indicator-application-service just like Ubuntu MATE, so it can be the same as Desktop notifications denied in Ubuntu MATE.

FYI the issue is being tracked in https://github.com/Arnatious/qbittorrent-snap/issues/2 as well. Long ago I tried seeing if the kde base snaps would help but they were not available for core20 at the time. I’ll try investigating those again.

From what my investigations wrought, the tray icon isn’t getting set. Stderr shows a clear message of

QSystemTrayIcon::setVisible: No Icon set

It might be a dbus issue, but I’m not an expert in Qt or desktop apps so it’s beyond me to solve.

I believe the source of the issue is here

It tries to get the icon from icon theme, but icons in the snap and on the host are different and snap doesn’t mount icons from the host, so this will never work reliably.

I.e. it should be enough to replace #if defined(Q_OS_UNIX) with #if 0 to fix the issue

Or add a check for being in snap if you plan to upstream your change

The changes in https://github.com/Arnatious/qbittorrent-snap/pull/12 have fixed the tray icon issues for both KDE Neon and Ubuntu Gnome.

Adding the KDE framework snap was enough to provide the correct theming and icons. The changes in the linked PR are the equivalent of adding the kde-neon extension, which is amd64 only because the core18 frameworks aren’t published for arm64.

For anyone reading this with a similar problem, snapcraft expand-extensions when using the kde-neon extension with a core20 snap will get you the yaml you need to get it working on amd64 and arm64, just make the changes manually and remove the extension afterwards.

No luck for 32bit users (who are still a decent chunk of my qbittorrent users).