diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 3342f29614..470b3f4614 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1448,16 +1448,22 @@ void QCocoaWindow::recreateWindowIfNeeded() { QMacAutoReleasePool pool; + QPlatformWindow *parentWindow = QPlatformWindow::parent(); + auto *parentCocoaWindow = static_cast(parentWindow); + if (isForeignWindow()) { // A foreign window is created as such, and can never move between being // foreign and not, so we don't need to get rid of any existing NSWindows, // nor create new ones, as a foreign window is a single simple NSView. qCDebug(lcQpaWindow) << "Skipping NSWindow management for foreign window" << this; + + // We do however need to manage the parent relationship + if (parentCocoaWindow) + [parentCocoaWindow->m_view addSubview:m_view]; + return; } - QPlatformWindow *parentWindow = QPlatformWindow::parent(); - const bool isEmbeddedView = isEmbedded(); RecreationReasons recreateReason = RecreationNotNeeded; @@ -1495,8 +1501,6 @@ void QCocoaWindow::recreateWindowIfNeeded() if (recreateReason == RecreationNotNeeded) return; - QCocoaWindow *parentCocoaWindow = static_cast(parentWindow); - // Remove current window (if any) if ((isContentView() && !shouldBeContentView) || (recreateReason & PanelChanged)) { if (m_nsWindow) {