diff options
author | Sebastian Beckmann <beckmann.sebastian@outlook.de> | 2023-02-09 21:05:20 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-11 14:24:39 +0000 |
commit | 0b2ca3ee3ef2fe7edfb9d8fe2d0f0e6306ffdbd5 (patch) | |
tree | 65abb358ef84e2fb71a1d9ce03eca3a4cca94aa6 /tests | |
parent | d1a32dfcef9ea9cda4a08ef7f6b34ad9939473e5 (diff) |
QAbstractItemView: Don't unselect on click on empty area in SingleSelect
dfb4697e4a4828acd47292a89207b3975ec6766e made a change to selection
behavior that resulted in a regression where clicking on an item view
but not on an item would cause the current item to get unselected.
Changes the behavior to not update in this case.
Added a new test that specifially checks for this scenario and ensures
that the current item is still selected, even after the user clicks on
empty area.
Fixes: QTBUG-105870
Change-Id: I191c3878819b99897083039fba0ab43908da5429
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit f11e5435c776deddf27f7759180c1d41f64b8cce)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 47f8ab4be8..adb000fe53 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -165,6 +165,7 @@ private slots: void selectionCommand(); void mouseSelection_data(); void mouseSelection(); + void keepSingleSelectionOnEmptyAreaClick(); void scrollerSmoothScroll(); void inputMethodOpensEditor_data(); void inputMethodOpensEditor(); @@ -3096,6 +3097,37 @@ void tst_QAbstractItemView::mouseSelection() } /*! + Make sure that when clicking on empty space in the view, we don't + unselect the current row. + QTBUG-105870 +*/ +void tst_QAbstractItemView::keepSingleSelectionOnEmptyAreaClick() +{ + QListWidget view; + view.setSelectionMode(QAbstractItemView::SingleSelection); + QListWidgetItem *lastItem; + for (int i = 0; i < 5; i++) + lastItem = new QListWidgetItem("item " + QString::number(i), &view); + + // Make widget large enough so that there is empty area below the last item + view.setFixedSize(300, 500); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + // Select third row + view.setCurrentRow(2); + + // Click below the last row + QPoint targetPoint = view.visualItemRect(lastItem).bottomLeft(); + targetPoint += QPoint(10, 10); + + QTest::mouseClick(view.viewport(), Qt::MouseButton::LeftButton, Qt::NoModifier, targetPoint); + + QCOMPARE(view.currentRow(), 2); + QVERIFY(view.currentItem()->isSelected()); +} + +/*! Verify that scrolling an autoScroll enabled itemview with a QScroller produces a continuous, smooth scroll without any jumping around due to the currentItem negotiation between QAbstractItemView and QScroller. |