QSystemTrayIcon signals not emitting on mouse click in Ubuntu 19.04
-
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.
-
Hi,
What version of Qt do you have currently installed ?
What desktop environment are you using ? -
@anshah
My guess, not based on knowledge, is that there will be an issue with GNOME. Do we knowQSystemTrayIcon
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?
-
@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.
-
I'd check with the Ubuntu folks also since they are responsible for the package they provide.
-
@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
-
@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. -
@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.
-
-
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.