path: root/src/widgets/widgets/qmenu.cpp
diff options
authorTor Arne Vestbø <>2020-12-11 13:07:24 +0100
committerTor Arne Vestbø <>2021-01-04 10:47:45 +0100
commitc30d05e794e49d69cbc981ae2ff21e5713c5a81f (patch)
tree9e01eb5d50b58ad1a86e0c458b652d539796996e /src/widgets/widgets/qmenu.cpp
parent74559dccc84ed0f0f7d8f57165fe387c3e112485 (diff)
macOS: Simplify and fix issues with QMenuPrivate::moveWidgetToPlatformItem
View embedding when QWidget is involved is a bit finicky. This change breaks down the steps needed to embed it into an NSMenu item, and simplifies the process by not relying on a container widget. The main issue is that QCocoaWindow::recreateWindowIfNeeded() will potentially create an NSWindow for the embedded view, resulting in a stray view. To prevent this we set the Qt::SubWindow flag on the window, but QWidget tends to reset this flag when the widget doesn't have a parent, so we need to be careful about which order we do the setup. Pick-to: 6.0 5.15 Change-Id: I505f7c0a2d8e4350511fdb01a5e9b9c623a40a41 Reviewed-by: Timur Pocheptsov <>
Diffstat (limited to 'src/widgets/widgets/qmenu.cpp')
1 files changed, 1 insertions, 12 deletions
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index a8ec683638..1fb967ef8d 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -3588,19 +3588,8 @@ void QMenu::actionEvent(QActionEvent *e)
if (e->action() == d->currentAction)
d->currentAction = nullptr;
if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) {
- if (QWidget *widget = d->widgetItems.value(wa)) {
-#ifdef Q_OS_MACOS
- QWidget *p = widget->parentWidget();
- if (p != this) {
- // This widget was reparented into a container widget
- // (see QMenuPrivate::moveWidgetToPlatformItem).
- // Reset the parent and delete the native widget.
- widget->setParent(this);
- p->deleteLater();
- }
+ if (QWidget *widget = d->widgetItems.value(wa))
- }
d->widgetItems.remove(static_cast<QAction *>(e->action()));