diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-11-13 11:12:50 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-11-13 19:14:59 +0100 |
commit | db33628452c5ccbf07b901405fba74525f7192c9 (patch) | |
tree | 8a480081b4721e26835fb91105eb20c2ff8f0c91 /src/plugins/platforms/cocoa | |
parent | 93077dd1f237730a26714d77bb7e91542f96affc (diff) |
Ensure foreign window can be reparented out of contained window again
A foreign window embedded into a Qt hierarchy must also support
being removed from that window hierarchy.
Pick-to: 6.6
Change-Id: Id4d08079ff19d67a8989937bc72602e8bd14b31b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 3fbc06a089..748b8ef1c6 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1499,6 +1499,10 @@ void QCocoaWindow::recreateWindowIfNeeded() QPlatformWindow *parentWindow = QPlatformWindow::parent(); auto *parentCocoaWindow = static_cast<QCocoaWindow *>(parentWindow); + QCocoaWindow *oldParentCocoaWindow = nullptr; + if (QNSView *qnsView = qnsview_cast(m_view.superview)) + oldParentCocoaWindow = qnsView.platformWindow; + 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, @@ -1508,6 +1512,8 @@ void QCocoaWindow::recreateWindowIfNeeded() // We do however need to manage the parent relationship if (parentCocoaWindow) [parentCocoaWindow->m_view addSubview:m_view]; + else if (oldParentCocoaWindow) + [m_view removeFromSuperview]; return; } @@ -1515,10 +1521,6 @@ void QCocoaWindow::recreateWindowIfNeeded() const bool isEmbeddedView = isEmbedded(); RecreationReasons recreateReason = RecreationNotNeeded; - QCocoaWindow *oldParentCocoaWindow = nullptr; - if (QNSView *qnsView = qnsview_cast(m_view.superview)) - oldParentCocoaWindow = qnsView.platformWindow; - if (parentWindow != oldParentCocoaWindow) recreateReason |= ParentChanged; |