From e18eac95ad4b69ebe53e51c65416f1c94275e10a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 24 Mar 2009 11:10:06 +0100 Subject: Fixes a focusWidget when showing a toplevel that accepts keyboard input. When a toplevel window is the widget that can accept keyboard input, it doesn't get focus when shown. The fix is to check if the toplevel is activated and noone has focus, then give focus to the toplevel itself. Reviewed-by: Brad Task-number: 244607 --- src/gui/kernel/qapplication.cpp | 4 +++- tests/auto/qwidget/tst_qwidget.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 1bbb019..7e59fad 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -2461,7 +2461,9 @@ void QApplication::setActiveWindow(QWidget* act) } else { // If the focus widget is not in the activate_window, clear the focus w = QApplicationPrivate::focus_widget; - if (w && !QApplicationPrivate::active_window->isAncestorOf(w)) + if (!w && QApplicationPrivate::active_window->focusPolicy() != Qt::NoFocus) + QApplicationPrivate::setFocusWidget(QApplicationPrivate::active_window, Qt::ActiveWindowFocusReason); + else if (!QApplicationPrivate::active_window->isAncestorOf(w)) QApplicationPrivate::setFocusWidget(0, Qt::ActiveWindowFocusReason); } } diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 42f496a..dfd0792 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -343,6 +343,7 @@ private slots: void paintOutsidePaintEvent(); #endif void updateOnDestroyedSignal(); + void toplevelLineEditFocus(); private: bool ensureScreenSize(int width, int height); @@ -8727,5 +8728,18 @@ void tst_QWidget::updateOnDestroyedSignal() QTest::qWait(200); } +void tst_QWidget::toplevelLineEditFocus() +{ + testWidget->hide(); + + QLineEdit w; + w.show(); + qt_x11_wait_for_window_manager(&w); + QTest::qWait(200); + + QCOMPARE(QApplication::activeWindow(), &w); + QCOMPARE(QApplication::focusWidget(), &w); +} + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" -- cgit v0.12