summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorSebastian Beckmann <beckmann.sebastian@outlook.de>2023-02-09 21:05:20 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-02-11 12:47:24 +0100
commitf11e5435c776deddf27f7759180c1d41f64b8cce (patch)
tree99f6cbd121cddb70febdc5683c206c5d2f4db726 /src/widgets/itemviews
parent9b30774ad37034a0eab3440cdce49e719ad50544 (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 Pick-to: 6.2 6.4 6.5 Change-Id: I191c3878819b99897083039fba0ab43908da5429 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 1619635dbf..179e542ccc 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -4093,8 +4093,12 @@ QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QM
if (d->pressedAlreadySelected)
return QItemSelectionModel::NoUpdate;
break;
- case QEvent::KeyPress:
case QEvent::MouseButtonRelease:
+ // clicking into area with no items does nothing
+ if (!index.isValid())
+ return QItemSelectionModel::NoUpdate;
+ Q_FALLTHROUGH();
+ case QEvent::KeyPress:
// ctrl-release on selected item deselects
if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index))
return QItemSelectionModel::Deselect | d->selectionBehaviorFlags();