QSystemTrayIcon woes



  • Hello!
    I want my application to display its (simplified) current status in the system notification area. For this I want to generate icon image manually.

    The code I have problems was simplified down to this:

    QPixmap *iconPixmap = new QPixmap (TRAY_ICON_SIZE, TRAY_ICON_SIZE);
    iconPixmap->fill (Qt::white);
    tray.setIcon (QIcon (*iconPixmap));

    In KDE on Fedora 25 I can see only a empty transparent placeholder in system notification area. In Windows I see the expected white square. On Ubuntu with Unity I see the white square in wrong place (in the top-left corner of the screen ???).

    I found that to set the icon is first written to /tmp/sni-qt_<app>_<pid>-<XXX>/ directory as a png file. I can see my white square in the PNG file there, but there's no white square in the system notification area.

    Then I found something completely disturbing. I simplified my application to something even simpler, I replaced my whole code to just:

    QIcon icon (":/icons/magic-wand");
    tray.setIcon (icon);

    where /icons/magic-want is a resource file used elsewhere in my application. Now I can again find the PNG file under /tmp/sni-qt-*/ directory, but the system notification area is still empty!

    Then I tried other icons from my resources and found that some will show in notification area, and some won't. This is real magic, I can't get why some resource icons will show up, and some won't. I can see no difference between them.

    Here are them:
    the icon that shows in notification area is http://cs.ozerki.net/zap/ok.png
    and the one that doesn't is http://cs.ozerki.net/zap/bad.png

    The icon is loaded from resource, because isNull() returns false in both cases and I can see the png file under /tmp in both cases.

    What's wrong with the second PNG file? Why it doesn't show in KDE but shows in other window managers? This is quite strange.


  • Qt Champions 2017

    Hi
    Did you try to scale "bad" to 64x64 ?
    its the only difference i can see.



  • You are indeed right, the size is the key difference. 64x64 and larger image will show, and smaller images won't. This is very, very, very strange. Looks like KDE likes to resize notification area icons.

    However, other Qt applications (for example, PSI) use 22x22 PNG files (as recommended by QSystemTrayIcon docs, btw) and show up normally.

    After I changed my QPixmap to 64x64 size, the synthesized icon shows normally in Fedora, but I still have to check up with other OSes/window managers, because as practice shows, tray API is very fragile.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.