summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-06-02 15:24:25 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-06-08 00:10:42 +0200
commitefdaba37d61e82f27a7bcbb49e176313452f59f9 (patch)
tree1f8c25617f7bcda5b1776b17981bbe336859df50 /src/widgets/itemviews
parent8654192f8fe54512f17deeeb312e892b2e964a4f (diff)
QAItemView: in MultiSelection, press deselects only if no drag can start
In MultiSelection mode, items are by default toggled on press, which follows the example of standard Windows controls. However, when dragging is enabled, then the press might be the beginning of a drag'n'drop operation, and deselecting the item on press breaks the selection and user experience. Don't toggle the selection for presses on an already selected item that might get dragged; instead, wait for the release event. Extend the test case slightly to cover the special case. Dragging a selection in a drag-enabled and MultiSelection item view wasn't possible before either. Fixes: QTBUG-59888 Change-Id: Ibd3e95a71ea63dd1e9bc3c8a723eafa9a1c21afa Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: David Skoland <david.skoland@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index f4f41e6f68..8a923e44a7 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -3981,16 +3981,23 @@ QItemSelectionModel::SelectionFlags QAbstractItemViewPrivate::multiSelectionComm
return QItemSelectionModel::Toggle|selectionBehaviorFlags();
break;
case QEvent::MouseButtonPress:
- if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
- return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle
+ if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) {
+ // since the press might start a drag, deselect only on release
+ if (!pressedAlreadySelected || !dragEnabled || !isIndexDragEnabled(index))
+ return QItemSelectionModel::Toggle|selectionBehaviorFlags(); // toggle
+ }
break;
case QEvent::MouseButtonRelease:
- if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton)
+ if (static_cast<const QMouseEvent*>(event)->button() == Qt::LeftButton) {
+ if (pressedAlreadySelected && dragEnabled && isIndexDragEnabled(index) && index == pressedIndex)
+ return QItemSelectionModel::Toggle|selectionBehaviorFlags();
return QItemSelectionModel::NoUpdate|selectionBehaviorFlags(); // finalize
+ }
break;
case QEvent::MouseMove:
if (static_cast<const QMouseEvent*>(event)->buttons() & Qt::LeftButton)
return QItemSelectionModel::ToggleCurrent|selectionBehaviorFlags(); // toggle drag select
+ break;
default:
break;
}