From c30d05e794e49d69cbc981ae2ff21e5713c5a81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 11 Dec 2020 13:07:24 +0100 Subject: 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 --- src/widgets/widgets/qmenu.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/widgets/widgets/qmenu.cpp') 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(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(); - } -#endif + if (QWidget *widget = d->widgetItems.value(wa)) wa->releaseWidget(widget); - } } d->widgetItems.remove(static_cast(e->action())); } -- cgit v1.2.3