QCocoaWindow: Make window key if the app's modal window is hidden
On macOS, when showing a window, we decide if it should be made key and therefore active, if the app has no active modal session or if the window's worksWhenModal returns true. However, the window needs to be made key also when a modal window is present, but not visible. Add this condition when checking if the window needs to be made key. This makes the behavior consistent with what happens when a modal is minimized on macOS. The input focus is passed to the next window, and the window appears active, even if it can not be interacted with. Fixes: QTBUG-85574 Pick-to: 5.15 6.2 Change-Id: I204d4f912128f4a46840789fc2ee08e1b2716bfc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
c1281c306c
commit
911c97f2b5
@ -365,7 +365,9 @@ void QCocoaWindow::setVisible(bool visible)
|
||||
// Show the window as application modal
|
||||
eventDispatcher()->beginModalSession(window());
|
||||
} else if (m_view.window.canBecomeKeyWindow) {
|
||||
bool shouldBecomeKeyNow = !NSApp.modalWindow || m_view.window.worksWhenModal;
|
||||
bool shouldBecomeKeyNow = !NSApp.modalWindow
|
||||
|| m_view.window.worksWhenModal
|
||||
|| !NSApp.modalWindow.visible;
|
||||
|
||||
// Panels with becomesKeyOnlyIfNeeded set should not activate until a view
|
||||
// with needsPanelToBecomeKey, for example a line edit, is clicked.
|
||||
|
@ -437,6 +437,8 @@ private slots:
|
||||
void setParentChangesFocus_data();
|
||||
void setParentChangesFocus();
|
||||
|
||||
void activateWhileModalHidden();
|
||||
|
||||
private:
|
||||
const QString m_platform;
|
||||
QSize m_testWidgetSize;
|
||||
@ -12315,5 +12317,24 @@ void tst_QWidget::setParentChangesFocus()
|
||||
QCOMPARE(QApplication::focusWidget()->objectName(), focusWidget);
|
||||
}
|
||||
|
||||
void tst_QWidget::activateWhileModalHidden()
|
||||
{
|
||||
QDialog dialog;
|
||||
dialog.setWindowModality(Qt::ApplicationModal);
|
||||
dialog.show();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&dialog));
|
||||
QVERIFY(dialog.isActiveWindow());
|
||||
QCOMPARE(QApplication::activeWindow(), &dialog);
|
||||
|
||||
dialog.hide();
|
||||
QTRY_VERIFY(!dialog.isVisible());
|
||||
|
||||
QMainWindow window;
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&window));
|
||||
QVERIFY(window.isActiveWindow());
|
||||
QCOMPARE(QApplication::activeWindow(), &window);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QWidget)
|
||||
#include "tst_qwidget.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user