Search code examples
c++macosqtsystem-tray

Qt system tray icon disappears when menu opened on OSX 10.10


I have simple qt code:

sticon = new QSystemTrayIcon(this);
QIcon icon(":/music.png");
sticon->setIcon(icon);

QMenu* stmenu = new QMenu(NULL);
action = new QAction("test",NULL);
stmenu->addAction(action);
sticon->setContextMenu(stmenu);
sticon->show();
connect(action, SIGNAL(triggered()), this, SLOT(clickText()));

And when I click on the menu, I get errors and Tray icon disappears:

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted

It works on OSX 10.10 + Qt 5.4 What is the problem?


Solution

  • This is Qt 5.4 bug:

    On Mac OS X 10.9.5, run QSystemTrayIcon example included in the Qt installation. Click on the icon shown on the menu bar to activate the menu. Then click elsewhere to deactiviate it. The icon goes blank on the menu bar. If you click on the blank space again, the icon re-appears.

    https://bugreports.qt-project.org/browse/QTBUG-42910?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel