diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-03-07 13:32:28 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-03-28 14:30:50 +0000 |
commit | a7747300849b2f931c5ac18ecbfaae7b08432cc7 (patch) | |
tree | 0af309555302f294930cb7820b94ff671d895626 | |
parent | 72d703a521438c0e99e2e12edf4d6abaec2e6fe1 (diff) | |
download | qtbase-a7747300849b2f931c5ac18ecbfaae7b08432cc7.tar.gz |
macOS: Create NSView as initially hidden, to match QWindow behavior
Initially attempted in 096b56f336e5bb994d46f073d55496d36d38e6b1,
but that broke QQuickWindow::grabWindow(), which at the time was
not prepared for grabbing non-visible windows.
This is no longer an issue, as QQuickWindow::grabWindow() has fallback
logic for non-renderable windows. QWidget::grab() also works fine,
as it grabs from the backingstore directly.
For top level windows we apply the visibility state to both the
NSWindow (orderIn/Out), and to the NSView (hidden=YES/NO).
Change-Id: I617b292ca6bfba66e65b55941c5b002e415da88d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit a4bd121125dade1a0c292284836ea52617ba77c0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 15 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 7 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 50577bfe2b..28f6a8a29e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -338,6 +338,9 @@ void QCocoaWindow::setVisible(bool visible) } + // Make the NSView visible first, before showing the NSWindow (in case of top level windows) + m_view.hidden = NO; + if (isContentView()) { QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); @@ -375,13 +378,6 @@ void QCocoaWindow::setVisible(bool visible) } } } - - // In some cases, e.g. QDockWidget, the content view is hidden before moving to its own - // Cocoa window, and then shown again. Therefore, we test for the view being hidden even - // if it's attached to an NSWindow. - if ([m_view isHidden]) - [m_view setHidden:NO]; - } else { // Window not visible, hide it if (isContentView()) { @@ -410,10 +406,10 @@ void QCocoaWindow::setVisible(bool visible) if (mainWindow && [mainWindow canBecomeKeyWindow]) [mainWindow makeKeyWindow]; } - } else { - [m_view setHidden:YES]; } + m_view.hidden = YES; + if (parentCocoaWindow && window()->type() == Qt::Popup) { NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow(); if (m_resizableTransientParent @@ -1514,7 +1510,6 @@ void QCocoaWindow::recreateWindowIfNeeded() } else if (parentWindow) { // Child windows have no NSWindow, re-parent to superview instead [parentCocoaWindow->m_view addSubview:m_view]; - [m_view setHidden:!window()->isVisible()]; } } diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index f8c17e179d..bd32d729a5 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -118,6 +118,13 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper); if ((self = [super initWithFrame:NSZeroRect])) { m_platformWindow = platformWindow; + // NSViews are by default visible, but QWindows are not. + // We should ideally pick up the actual QWindow state here, + // but QWindowPrivate::setVisible() expects to control the + // order of events tightly, so we need to wait for a call + // to QCocoaWindow::setVisible(). + self.hidden = YES; + self.focusRingType = NSFocusRingTypeNone; self.previousSuperview = nil; |