summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2015-01-11 12:05:55 +0300
committerShawn Rutledge <shawn.rutledge@digia.com>2015-01-22 21:41:16 +0100
commit03dc2b2e82750d1c531cf00a406368cde4a8928b (patch)
tree8890549d37e9250d236fa64e2a4bda0a5c2b2830
parent2b5df245d6cdbfb3150ee815debccf655af8f19f (diff)
QSystemTrayIcon: handle submenus correctly
This fixes a bug when submenus are shown as simple actions when a platform system tray icon is used. To correctly handle submenus, we need to set platform menus on all submenus, and only then on a parent menu. Change-Id: If2bfcc703b938dbb14ba4b9aa810039ced07e946 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: Dimitrios Glentadakis <dglent@free.fr> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r--src/widgets/util/qsystemtrayicon.cpp28
-rw-r--r--src/widgets/util/qsystemtrayicon_p.h1
2 files changed, 24 insertions, 5 deletions
diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp
index 7d04cab05e..d151e57d04 100644
--- a/src/widgets/util/qsystemtrayicon.cpp
+++ b/src/widgets/util/qsystemtrayicon.cpp
@@ -37,6 +37,7 @@
#ifndef QT_NO_SYSTEMTRAYICON
#include "qmenu.h"
+#include "qlist.h"
#include "qevent.h"
#include "qpoint.h"
#include "qlabel.h"
@@ -704,11 +705,7 @@ void QSystemTrayIconPrivate::updateIcon_sys_qpa()
void QSystemTrayIconPrivate::updateMenu_sys_qpa()
{
if (menu) {
- if (!menu->platformMenu()) {
- QPlatformMenu *platformMenu = qpa_sys->createMenu();
- if (platformMenu)
- menu->setPlatformMenu(platformMenu);
- }
+ addPlatformMenu(menu);
qpa_sys->updateMenu(menu->platformMenu());
}
}
@@ -741,6 +738,27 @@ void QSystemTrayIconPrivate::showMessage_sys_qpa(const QString &message,
static_cast<QPlatformSystemTrayIcon::MessageIcon>(icon), msecs);
}
+void QSystemTrayIconPrivate::addPlatformMenu(QMenu *menu) const
+{
+ if (menu->platformMenu())
+ return; // The platform menu already exists.
+
+ // The recursion depth is the same as menu depth, so should not
+ // be higher than 3 levels.
+ QListIterator<QAction *> it(menu->actions());
+ while (it.hasNext()) {
+ QAction *action = it.next();
+ if (action->menu())
+ addPlatformMenu(action->menu());
+ }
+
+ // This menu should be processed *after* its children, otherwise
+ // setMenu() is not called on respective QPlatformMenuItems.
+ QPlatformMenu *platformMenu = qpa_sys->createMenu();
+ if (platformMenu)
+ menu->setPlatformMenu(platformMenu);
+}
+
QT_END_NAMESPACE
#endif // QT_NO_SYSTEMTRAYICON
diff --git a/src/widgets/util/qsystemtrayicon_p.h b/src/widgets/util/qsystemtrayicon_p.h
index 0dda689c51..f05bf9e3f9 100644
--- a/src/widgets/util/qsystemtrayicon_p.h
+++ b/src/widgets/util/qsystemtrayicon_p.h
@@ -99,6 +99,7 @@ private:
void updateMenu_sys_qpa();
QRect geometry_sys_qpa() const;
void showMessage_sys_qpa(const QString &msg, const QString &title, QSystemTrayIcon::MessageIcon icon, int secs);
+ void addPlatformMenu(QMenu *menu) const;
};
class QBalloonTip : public QWidget