Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSystemTrayIcon signals not emitting on mouse click in Ubuntu 19.04
Forum Updated to NodeBB v4.3 + New Features

QSystemTrayIcon signals not emitting on mouse click in Ubuntu 19.04

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anshah
    wrote on last edited by anshah
    #1

    I have just installed Ubuntu 19.04 and I'm using the Qt distribution it provides in the apt-get repo. I'm seeing that the QSytemTrayIcon signals do not emit upon mouse click. I'm aware of the issues with "activated" signal so I also connected a slot to listen to the "aboutToShow" signal from the QSystemTrayIcon's context menu which also should emit on mouse click. Neither of these signals are going out.

    Here's my code for the QSystemTrayIcon:

    // Create tray and setup tray icon
    void MyClass::createTrayIcon()
    {
        m_pTrayIconMenu = new QMenu(this);
        m_pTrayImage    = new QPixmap(IMG_SMALL_NOT_CONNECTED);
        m_pTrayIcon     = new QSystemTrayIcon(this);
    
        m_pTrayIcon->setContextMenu(m_pTrayIconMenu);
    
        QIcon icon(*m_pTrayImage);
        m_pTrayIcon->setIcon(icon);
        setWindowIcon(icon);
        m_pTrayIcon->show();
    
        connect(m_pTrayIconMenu, SIGNAL(aboutToShow()),
                this,            SLOT(onActivated()));
        connect(m_pTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
                this,        SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
    }
    
    // Slot to handle context menu aboutToShow signal
    void MyClass::onActivated()
    {
        if (!this->isVisible())
        {
            this->show();
        }
        else
        {
            this->hide();
        }
    }
    
    // Slot to handle tray icon activated signal
    void MyClass::onActivated(QSystemTrayIcon::ActivationReason r)
    {
        if (r == QSystemTrayIcon::Trigger)
        {
            if (!this->isVisible())
            {
                this->show();
            }
            else
            {
                this->hide();
            }
        }
    }
    

    In Ubuntu 18.04, the signals all emitted and everything was working fine. In Ubuntu 19.04 the signals do not emit.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt do you have currently installed ?
      What desktop environment are you using ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What version of Qt do you have currently installed ?
        What desktop environment are you using ?

        A Offline
        A Offline
        anshah
        wrote on last edited by anshah
        #3

        @SGaist I am using Gnome on Ubuntu 19.04. The Qt version is 5.12. It is the one provided with the distribution.

        JonBJ 1 Reply Last reply
        0
        • A anshah

          @SGaist I am using Gnome on Ubuntu 19.04. The Qt version is 5.12. It is the one provided with the distribution.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @anshah
          My guess, not based on knowledge, is that there will be an issue with GNOME. Do we know QSystemTrayIcon works properly under GNOME? See e.g. https://stackoverflow.com/a/45151259 or https://forum.qt.io/topic/107210/qsystemtrayicon-activated-signal-only-sends-on-double-click-ubuntu-gnome.

          In Ubuntu 18.04, the signals all emitted and everything was working fine. In Ubuntu 19.04 the signals do not emit.

          Hmm, good point, Were you definitely using GNOME under your 18.04, they only changed off Unity at 17.10 I think. Does 19.04 have a different GNOME?

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @anshah
            My guess, not based on knowledge, is that there will be an issue with GNOME. Do we know QSystemTrayIcon works properly under GNOME? See e.g. https://stackoverflow.com/a/45151259 or https://forum.qt.io/topic/107210/qsystemtrayicon-activated-signal-only-sends-on-double-click-ubuntu-gnome.

            In Ubuntu 18.04, the signals all emitted and everything was working fine. In Ubuntu 19.04 the signals do not emit.

            Hmm, good point, Were you definitely using GNOME under your 18.04, they only changed off Unity at 17.10 I think. Does 19.04 have a different GNOME?

            A Offline
            A Offline
            anshah
            wrote on last edited by
            #5

            @JonB
            Ubuntu 19.04 uses Gnome 3.32.1
            Ubuntu 18.04 uses Gnome 3.28.2

            Again I had no issues with QSystemTrayIcon activated signal in 18.04.

            JonBJ jsulmJ 2 Replies Last reply
            0
            • A anshah

              @JonB
              Ubuntu 19.04 uses Gnome 3.32.1
              Ubuntu 18.04 uses Gnome 3.28.2

              Again I had no issues with QSystemTrayIcon activated signal in 18.04.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @anshah
              If you also used the Qt version provided with the 18.04 Ubuntu it may well be different? Then it might be Qt version or GNOME version issue.

              Either way, if you do not get an answer here, you should report, with minimal example, at https://bugreports.qt.io. Maybe someone there can help.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I'd check with the Ubuntu folks also since they are responsible for the package they provide.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A anshah

                  @JonB
                  Ubuntu 19.04 uses Gnome 3.32.1
                  Ubuntu 18.04 uses Gnome 3.28.2

                  Again I had no issues with QSystemTrayIcon activated signal in 18.04.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @anshah Ubuntu 18.04 uses Unity by default, not Gnome except you explicitly install and use it.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  JonBJ 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @anshah Ubuntu 18.04 uses Unity by default, not Gnome except you explicitly install and use it.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @jsulm
                    Dear js, that's not right! Do you have a reference for that?* 18.04 had moved over to GNOME. In fact, IIRC, it was at 17.10 that GNOME replaced Unity as the supplied default.

                    • E.g. https://www.omgubuntu.co.uk/2017/04/ubuntu-18-04-ship-gnome-desktop-not-unity
                    • https://en.wikipedia.org/wiki/Ubuntu:

                    GNOME 3 has been the default GUI for Ubuntu Desktop since Ubuntu 17.10,[42][43] while Unity is still the default in older versions,[44][45] including all current LTS versions except 18.04 LTS

                    jsulmJ 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @jsulm
                      Dear js, that's not right! Do you have a reference for that?* 18.04 had moved over to GNOME. In fact, IIRC, it was at 17.10 that GNOME replaced Unity as the supplied default.

                      • E.g. https://www.omgubuntu.co.uk/2017/04/ubuntu-18-04-ship-gnome-desktop-not-unity
                      • https://en.wikipedia.org/wiki/Ubuntu:

                      GNOME 3 has been the default GUI for Ubuntu Desktop since Ubuntu 17.10,[42][43] while Unity is still the default in older versions,[44][45] including all current LTS versions except 18.04 LTS

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @JonB Oh, you're right!

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @JonB Oh, you're right!

                        A Offline
                        A Offline
                        anshah
                        wrote on last edited by
                        #11

                        @jsulm @JonB @SGaist
                        How does support work? Do I call Qt? Ubuntu? GNome?

                        I posted this on an Ubuntu Forum and I literally saw tumbleweed going across. StackOverflow is useless too.

                        Over the past year you guys are the only ones who respond almost immediately and I'm super appreciative.
                        I consider you guys family.

                        JonBJ 1 Reply Last reply
                        0
                        • A anshah

                          @jsulm @JonB @SGaist
                          How does support work? Do I call Qt? Ubuntu? GNome?

                          I posted this on an Ubuntu Forum and I literally saw tumbleweed going across. StackOverflow is useless too.

                          Over the past year you guys are the only ones who respond almost immediately and I'm super appreciative.
                          I consider you guys family.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @anshah
                          I don't think you can call Qt company without a support contract :) And I don't think there's anyone to call for Ubuntu or GNOME :)

                          First, I suggested

                          Either way, if you do not get an answer here, you should report, with minimal example, at https://bugreports.qt.io. Maybe someone there can help.

                          Have you done that? That would be my first port of call.

                          Second, if this is a show-stopper for you, do you compile Qt yourself/are you prepared to? Because if I worked in C++ (I am Python) I would be prepared to get the sources of Qt into the debugger and have a mosey around, hoping I could break in the code at useful places.

                          1 Reply Last reply
                          1
                          • C Offline
                            C Offline
                            Chrisw01
                            wrote on last edited by
                            #13

                            @anshah I have noticed with various flavors of Linux that Qt is often behind the times. As @JonB says, you might be better off compiling. Or what I do is download the installer from Qt and install from that. I usually choose the latest few versions so I can have a few options to play with.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              anshah
                              wrote on last edited by anshah
                              #14

                              Sorry I haven't posted on this thread for a while since I got pulled off on other issues. So compiling Qt myself is not an option as we use the distribution provided by the repository "apt-get" in Ubuntu. The problematic Ubuntu version is 19.04 which also has an update to Gnome.

                              The main issue right now is that the QSystemTrayIcon does not send out any signals when receiving mouse clicks and is completely unresponsive.

                              Do you think it could somehow be sitting behind the system tray and somehow I need to bring it to the front?

                              QSystemTrayIcon is not a QWidget so it doesn't have any capability to capture QMouseEvents which I was hoping.

                              Do you guys have any ideas for workarounds to somehow capture mouse clicks?

                              I did see someone implement a small transparent QWidget window that fits over the QSystemTrayIcon and then it can capture the QMouseEvents and handle them appropriately. The only problem is that in order to get THAT working I need to use the geometry() method and I'm not sure that the QSystemTrayIcon's geometry() method returns anything. The last time I played around with it returned point (0,0). I'll try again.

                              QRect rect = trayIcon->geometry();
                              qDebug() << "Tray GEO: " << rect;
                              

                              This returns:

                              Tray GEO:  QRect(0,0 0x0)
                              

                              If you guys have any ideas of creative workarounds that would be great. Messing with Qt internals isn't an option unfortunately.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved