diff options
author | Viktor Arvidsson <viktor.arvidss@gmail.com> | 2024-01-17 10:19:01 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-29 12:36:16 +0100 |
commit | d9397479e6dfc2d7b73cab6dcbcda4cccdc20b8a (patch) | |
tree | bfe7b3671b1ae61d7e4fb1c7298a25b08c0c0943 /tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | |
parent | d7b71294e8267123595593efca397151e4bf2595 (diff) |
QAbstractItemView: Release tab focus when hidden
When hiding a widget that has focus we try to focus the next widget in
the focus chain by running focusNextPrevChild. The abstract item view
overrides this to step the items but does not account for this hide case
which makes focusing not only not work, but also by hiding the widget
the selection in the item view gets changed.
Pick-to: 6.7 6.6 6.5
Change-Id: I29d40a1fb86ced60ec742b2753a87383846a89b3
Reviewed-by: Viktor Arvidsson <viktor.arvidss@gmail.com>
Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp')
-rw-r--r-- | tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index d4ad780fa8..b221047798 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -151,6 +151,7 @@ private slots: void testSpinBoxAsEditor_data(); void testSpinBoxAsEditor(); void removeIndexWhileEditing(); + void focusNextOnHide(); private: static QAbstractItemView *viewFromString(const QByteArray &viewType, QWidget *parent = nullptr) @@ -3548,5 +3549,32 @@ void tst_QAbstractItemView::removeIndexWhileEditing() } } +void tst_QAbstractItemView::focusNextOnHide() +{ + QWidget widget; + QTableWidget table(10, 10); + table.setTabKeyNavigation(true); + QLineEdit lineEdit; + + QHBoxLayout layout; + layout.addWidget(&table); + layout.addWidget(&lineEdit); + widget.setLayout(&layout); + + widget.setTabOrder({&table, &lineEdit}); + + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + + QVERIFY(table.hasFocus()); + QCOMPARE(table.currentIndex(), table.model()->index(0, 0)); + QTest::keyPress(&table, Qt::Key_Tab); + QCOMPARE(table.currentIndex(), table.model()->index(0, 1)); + + table.hide(); + QCOMPARE(table.currentIndex(), table.model()->index(0, 1)); + QVERIFY(lineEdit.hasFocus()); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" |