diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-01-12 15:57:20 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-12-27 14:19:34 +0000 |
commit | a60d3e0df7085d077aaed93d9243cf3d57b59464 (patch) | |
tree | 6448d4009aa807b63d187c816cb71f9d99964054 | |
parent | 8a0f0553e4eb8468513bbb8ba45a9ec2bcd6ce68 (diff) | |
download | qtquickcontrols-a60d3e0df7085d077aaed93d9243cf3d57b59464.tar.gz |
TreeView: allow selecting items by touch
Only single items can be selected via an actual touchscreen, because
the keyboard modifiers are not accessible in a mouse event synthesized
from touch. With a mouse, if the system has a touchscreen, then
selections done by consecutive clicking (with or without modifiers)
will work, whereas dragging across a consecutive range will not work
because dragging is the same as flicking. But on systems which do
not have a touchscreen at all, the behavior is the same as before.
Task-number: QTBUG-47243
Change-Id: Ib0fa1a75592b982fe93da46f0c2e3018219947d0
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/controls/TreeView.qml | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/controls/TreeView.qml b/src/controls/TreeView.qml index aa21acc1..6a38acff 100644 --- a/src/controls/TreeView.qml +++ b/src/controls/TreeView.qml @@ -118,8 +118,8 @@ BasicTableView { z: -1 propagateComposedEvents: true focus: true - // Note: with boolean preventStealing we are keeping - // the flickable from eating our mouse press events + // If there is not a touchscreen, keep the flickable from eating our mouse drags. + // If there is a touchscreen, flicking is possible, but selection can be done only by tapping, not by dragging. preventStealing: !Settings.hasTouchScreen property var clickedIndex: undefined @@ -323,8 +323,22 @@ BasicTableView { modelAdaptor.collapse(modelIndex) else modelAdaptor.expand(modelIndex) - } else if (root.__activateItemOnSingleClick) { - root.activated(modelIndex) + } else { + if (Settings.hasTouchScreen) { + // compensate for the fact that onPressed didn't select on press: do it here instead + pressedIndex = modelAdaptor.mapRowToModelIndex(clickIndex) + pressedColumn = __listView.columnAt(mouseX) + selectOnRelease = false + __listView.forceActiveFocus() + __listView.currentIndex = clickIndex + if (!clickedIndex) + clickedIndex = pressedIndex + mouseSelect(pressedIndex, mouse.modifiers, false) + if (!mouse.modifiers) + clickedIndex = pressedIndex + } + if (root.__activateItemOnSingleClick && !mouse.modifiers) + root.activated(modelIndex) } root.clicked(modelIndex) } |