isamert
isamert

Reputation: 502

QSystemTrayIcon QMenu Submenu with Qt 5

I have a program which creates QMenu and adds QMenu to first menu. The program runs perfectly on qt4, but when I compile it with qt5, the submenu does not appear. Here is an example code:

QMenu *menu = this->menuBar()->addMenu("Menu");
QMenu *menu2 = menu->addMenu("Menu2");
QAction *act = menu2->addAction("act");

QSystemTrayIcon *qsti = new QSystemTrayIcon(this);
qsti->setContextMenu(menu);
qsti->show();

Menubar shows everything correctly but systemtrayicon fails to show submenu. Secreenshots: menubar systemtray

Here, you can see that there is no submenu in the second picture(systemtray). Is there any workaround to solve this issue? I'm on Ubuntu 15.04 with Qt 5.4.1.

Upvotes: 0

Views: 861

Answers (1)

Alexander Tyapkov
Alexander Tyapkov

Reputation: 5067

Step forward is:

QMenu *menu = this->menuBar()->addMenu("Menu");
QMenu *menu2 = new QMenu("Menu2", menu);
QAction *act = menu2->addAction("act");
menu->addMenu(menu2);

QSystemTrayIcon *icon = new QSystemTrayIcon(this);
icon->setContextMenu(menu);
icon->show();

Now it shows that there is action but on my Ubuntu it is displayed with some kind of bug. Can you try it?

Upvotes: 0

Related Questions