QSystemTrayIcon issue on Ubuntu 16.04



  • I'm using Qt 5.7.1 on Ubuntu 16.04. Basically I have an app which opens a widget when a click on tray icon is performed.
    However when I click on the tray an ugly empty menu is displayed and the signal is not emitted at all.

    This works on OSX 10.12.2, Windows 10 and Fedora 21, Gnome 3.14

    Can someone help me suggesting a workaround? It seems a Qt bug...

    The code is the following:

    main.cpp

    #include <QApplication>
    #include "mytray.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        myTray w;
    
        return a.exec();
    }
    

    mytray.h

    #pragma once
    
    #include <QSystemTrayIcon>
    
    class myTray : public QSystemTrayIcon
    {
        Q_OBJECT
    public:
        explicit myTray(QObject *parent=0);
    
    private slots:
        void showPopup(QSystemTrayIcon::ActivationReason);
    };
    

    mytray.cpp

    #include "mytray.h"
    #include <QMessageBox>
    
    myTray::myTray(QObject *parent)
        :QSystemTrayIcon(parent)
    {
        connect(this ,&QSystemTrayIcon::activated,
                this, &myTray::showPopup);
    
        //TODO: use an available icon
        setIcon(QPixmap(":/icon"));
    
        show();
    }
    
    void myTray::showPopup(QSystemTrayIcon::ActivationReason)
    {
            QMessageBox::information(nullptr, "Hello", "Hello");
    }
    

  • Lifetime Qt Champion

    Hi,

    Before calling it a Qt bug, you should test your application by building it with Ubuntu's provided Qt. They might have done customisation for their window manager.


  • Qt Champions 2016

    Just out of curiosity, is this on unity desktop ?



  • @mrjj
    Yes it is a unity desktop


  • Qt Champions 2016

    @cOld
    Ok, they often have to add stuff to Qt to make it work in unity due to its
    special nature.
    So only way forward is to check as
    @SGaist suggest with the Qt included in the distro.


Log in to reply
 

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