3

I'm developing an application, where I have a system tray icon. I'm trying to catch QSystemTrayIcon::DoubleClick in the system tray. For some reason I do not understand, I have been unable to catch. In its stead, I just get two QSystemTrayIcon::Trigger events. I have tried this using both Qt4 (v4.8.7) and Qt5 (v5.5.1). My platform is KDE/Plasma 5(v5.4.3), on Debian Testing. I have tested this even on LXDE available on Debian Testing.

So my question here is: is this a bug in Qt or some other issue else where?

/* My Header File */

class MyTrayIcon : public QSystemTrayIcon {
    Q_OBJECT

    public :
        NBTrayIcon();

    public slots:
        void handleActivation( QSystemTrayIcon::ActivationReason reason );

    private slots:
        void toggleVisible();
        void showInfo();
        void quit();

    Q_SIGNALS:
        void newWindow();
};

/* My Cpp File */

MyTrayIcon::MyTrayIcon() : QSystemTrayIcon() {

    setIcon( QIcon( ":/icons/newbreeze.png" ) );
    connect( this, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), this, SLOT( handleActivation( QSystemTrayIcon::ActivationReason ) ) );

    QMenu *menu = new QMenu( "TrayMenu" );
    menu->addAction( "&Toggle Visible Windows", this, SLOT( toggleVisible() ) );
    menu->addAction( QIcon::fromTheme( "application-exit", QIcon( ":/icons/delete.png" ) ), "&Quit NewBreeze", this, SLOT( quit() ) );
    setContextMenu( menu );
};

void MyTrayIcon::handleActivation( QSystemTrayIcon::ActivationReason reason ) {

    qDebug() << reason;

    switch( reason ) {
        case MyTrayIcon::Context: {
            qDebug() << "Context";
            break;
        };

        case MyTrayIcon::MiddleClick: {
            qDebug() << "Middle Click";
            break;
        };

        case MyTrayIcon::Trigger: {
            qDebug() << "Trigger";
            break;
        }

        case MyTrayIcon::DoubleClick: {
            qDebug() << "DoubleClick";
            break;
        };

        default:{
            qDebug() << reason;
            break;
        };
    };
};

PS: I have added the code as listed above.

Marcus
  • 1,685
  • 1
  • 18
  • 33
  • Can you show some code? Do you check for `QSystemTrayIcon::ActivationReason`? https://doc.qt.io/qt-5/qsystemtrayicon.html#ActivationReason-enum – gengisdave Feb 08 '16 at 06:45
  • @gengisdave Sorry for not including the code. There made an edit. `QSystemTrayIcon::ActivationReason` is precisely what I am talking about. The above code not withstanding, I did try the `systray` example from the Qt sources with small modifications to differentiate between `Trigger` and `DoubleClick`. In both the cases, above and systray, `DoubleClick` results in two `Trigger` events. – Marcus Feb 08 '16 at 17:49

0 Answers0