1

I am using QSystemTrayIcon for the first time, and it was trivial to implement. My code looks like this:

if(!connect(mTrayIcon, &QSystemTrayIcon::activated, this, &MiniStudio::onTrayActivated)) {
    qWarning()<<"ERROR: could not connect QSystemTrayIcon";
}

mTrayIcon->setIcon(QIcon(":/icons/record.svg"));
mTrayIcon->setToolTip("Show MiniStudio controls");
mTrayIcon->setContextMenu(nullptr);
mTrayIcon->show();

As you probably understand from my code I don't want to display a context menu, I simply want a button in the tray that when clicked shows my application window.

The code sort of works, however, even if I specify a "nullptr" context menu, there still is a strange-looking box appearing under my tray icon whenever I click it, as if there is a context menu without any items in it (please see screenshot below).

Strange looking box under QSystemTrayIcon

So my questions are:

  • Am I doing something wrong?
  • How can I make the strange box go away?
  • Is this a bug, or maybe a feature of Qt on my platform?

PS: I am developing this code for Ubuntu 16.04 amd64 but I think the answer to this question should be relevant to any platform.

NOTE: I have also tried just omitting the setContextMenu() call instead of calling it with nullptr, and that didn't work either. The result was exactly the same.

Any input welcome,

Thank you!

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
  • i opened "System Tray Icon Example" from Qt examples, and commented the line "trayIcon->setContextMenu(trayIconMenu);" out from "createTrayIcon" function, it looks like it works on Windows 10. did you try it out? – sddk Mar 24 '17 at 06:50
  • I don't have access to Windows, sorry. I am guessing this is a bug in Qt! – Mr. Developerdude Mar 24 '17 at 08:25
  • I think what @sddk means is comment out the `setContextMenu` instead of setting it to `nullptr` and test it on your ubuntu machine. also it might not be a bug in Qt but maybe your window manager or whatever (Gnome?), who knows. – xander Mar 24 '17 at 08:27
  • Ah. That is what i tried first. I should have mentioned it. – Mr. Developerdude Mar 24 '17 at 08:28

0 Answers0