From 436a71e8950ea5a050f95b5889b85e5fafb2e716 Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Tue, 30 Jun 2009 22:50:48 +0200 Subject: Set the focus to a child widget when set on a QGroupBox When the focus is set on a QGroupBox with the policy NoFocus, the focus should be propagated to one of the child if it accepts the focus. This was failing because QWidget::focusWidget() returns the QGroupBox itself. Task-number: 257158 Reviewed-by: Denis --- src/gui/widgets/qgroupbox.cpp | 5 ++--- tests/auto/qgroupbox/tst_qgroupbox.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qgroupbox.cpp b/src/gui/widgets/qgroupbox.cpp index 0bfa8c0..2380e78 100644 --- a/src/gui/widgets/qgroupbox.cpp +++ b/src/gui/widgets/qgroupbox.cpp @@ -431,7 +431,7 @@ void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason) { Q_Q(QGroupBox); QWidget *fw = q->focusWidget(); - if (!fw) { + if (!fw || fw == q) { QWidget * best = 0; QWidget * candidate = 0; QWidget * w = q; @@ -449,8 +449,7 @@ void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason) } if (best) fw = best; - else - if (candidate) + else if (candidate) fw = candidate; } if (fw) diff --git a/tests/auto/qgroupbox/tst_qgroupbox.cpp b/tests/auto/qgroupbox/tst_qgroupbox.cpp index 2fa553f..3b94851 100644 --- a/tests/auto/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/qgroupbox/tst_qgroupbox.cpp @@ -80,6 +80,7 @@ private slots: void clicked(); void toggledVsClicked(); void childrenAreDisabled(); + void propagateFocus(); private: bool checked; @@ -459,5 +460,15 @@ void tst_QGroupBox::childrenAreDisabled() } } +void tst_QGroupBox::propagateFocus() +{ + QGroupBox box; + QLineEdit lineEdit(&box); + box.show(); + box.setFocus(); + QTest::qWait(250); + QCOMPARE(qApp->focusWidget(), &lineEdit); +} + QTEST_MAIN(tst_QGroupBox) #include "tst_qgroupbox.moc" -- cgit v0.12