summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-10-06 15:50:29 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-10-16 17:22:21 +0000
commitac35f9c44c0fb3b2f40ae5585c497200b2ba743d (patch)
treeadcb532550ace44bdf3115b5e465e09aa44ed292
parented9340a926aabcf3bf98091ed0436d6b02dd2c14 (diff)
macOS: Mark the widget's container as embedded when placed into NSMenuItemv5.10.0-beta2
Otherwise we'll end up creating a NSPanel for the QMacNativeWidget which is never closed, even if the backing NSView is moved to a new superview. Ideally this would be based on [NSView viewDidMoveToSuperview] and [NSView viewDidMoveToWindow], with retain/releases of the corresponding NSWindow, but that needs more research, especially as AppKit on macOS 10.13 will always keep a strong reference to the NSWindow. Task-number: QTBUG-63443 Change-Id: I9eec5ea871373d00dedf154600bf7005898cf37a Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm2
-rw-r--r--src/widgets/widgets/qmenu_mac.mm5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 3b6e55f654..8e5a9268ec 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -1240,7 +1240,7 @@ void QCocoaWindow::recreateWindowIfNeeded()
if (m_windowModality != window()->modality())
recreateReason |= WindowModalityChanged;
- const bool shouldBeContentView = !parentWindow && !m_viewIsEmbedded;
+ const bool shouldBeContentView = !parentWindow && !(m_viewIsToBeEmbedded || m_viewIsEmbedded);
if (isContentView() != shouldBeContentView)
recreateReason |= ContentViewChanged;
diff --git a/src/widgets/widgets/qmenu_mac.mm b/src/widgets/widgets/qmenu_mac.mm
index 7d932c670f..0d680fb4dc 100644
--- a/src/widgets/widgets/qmenu_mac.mm
+++ b/src/widgets/widgets/qmenu_mac.mm
@@ -135,6 +135,11 @@ void QMenuPrivate::moveWidgetToPlatformItem(QWidget *widget, QPlatformMenuItem*
containerWindow->setFlags(wf | Qt::SubWindow);
[(NSView *)widget->winId() setAutoresizingMask:NSViewWidthSizable];
+ if (QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setEmbeddedInForeignView")) {
+ typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded);
+ reinterpret_cast<SetEmbeddedInForeignViewFunction>(function)(containerWindow->handle(), true);
+ }
+
item->setNativeContents((WId)containerView);
container->show();
}