diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 824603be98d..93b7169237a 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1226,15 +1226,18 @@ void QCocoaWindow::windowDidResignKey() if (isForeignWindow()) return; - // Key window will be non-nil if another window became key, so do not - // set the active window to zero here -- the new key window's - // NSWindowDidBecomeKeyNotification hander will change the active window. - NSWindow *keyWindow = [NSApp keyWindow]; - if (!keyWindow || keyWindow == m_view.window) { - // No new key window, go ahead and set the active window to zero - if (!windowIsPopupType()) - QWindowSystemInterface::handleWindowActivated( - nullptr, Qt::ActiveWindowFocusReason); + // The current key window will be non-nil if another window became key. If that + // window is a Qt window, we delay the window activation event until the didBecomeKey + // notification is delivered to the active window, to ensure an atomic update. + NSWindow *newKeyWindow = [NSApp keyWindow]; + if (newKeyWindow && newKeyWindow != m_view.window + && [newKeyWindow conformsToProtocol:@protocol(QNSWindowProtocol)]) + return; + + // Lost key window, go ahead and set the active window to zero + if (!windowIsPopupType()) { + QWindowSystemInterface::handleWindowActivated( + nullptr, Qt::ActiveWindowFocusReason); } }