Michael
Michael

Reputation: 5335

QSystemTrayIcon: works in KDE and Windows, but not in Gnome Fallback/XFCE

I have a small application that uses QSystemTrayIcon to show information in balloon. It works fine in Windows and in KDE, but doesn't in Gnome Fallback and XFCE. Here is how it looks in KDE when clicked:

enter image description here

And here is what's happening when clicking it in Gnome Fallback: it is clicked with left mouse button, but behaves like it was clicked with right button, i.e. shows "Exit", and when clicked by right button, shows "About":

enter image description here

Is there a way to make the icon work in every DE?

Here is the code:

MyTray::MyTray(QObject *parent) :
      QObject(parent)
{
//..........
    menu.addAction(new QAction("Выход",this));
    connect(menu.actions()[0],SIGNAL(triggered()),this,SLOT(delete_itself()));
    icn=QIcon(":new/prefix1/08-01.png");
    icon.setIcon(icn);
    icon.setContextMenu(&menu);
    connect(&icon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(icon_clicked(QSystemTrayIcon::ActivationReason)));
    icon.show();
//..........
}
void MyTray::icon_clicked(QSystemTrayIcon::ActivationReason reason)
{
    if(reason==QSystemTrayIcon::Trigger)
    {
        QString s;
        for(int i=0;i<vec.count();i++)
        {
            s.append(vec[i].room);
            s.append(vec[i].isOpen ? ": открыт" : ": закрыт");
            if(vec.count()-1>i) s.append("\n");
        }
        QSystemTrayIcon::MessageIcon ic = QSystemTrayIcon::MessageIcon(QSystemTrayIcon::Information);
        icon.showMessage("Состояние",s,ic,20000);
    }
}

Upvotes: 1

Views: 497

Answers (1)

Michael
Michael

Reputation: 5335

Answering to myself. In GNOME and its derivatives, the only supported action for tray icon is context menu, unlike KDE where the icon can be also activated by the left click. There is a package sni-qt, that can add a point "Activate" to the context menu. I've installed this package and added to ~/.config/sni-qt.conf:

[need-activate-action]
itray

where itray is my app. So now it's possible to do what I wanted in two mouse clicks instead of one.

Upvotes: 1

Related Questions