aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2022-05-25 15:29:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-05-30 13:43:12 +0000
commitbaad186daf64d059f0e67d93c55f3aa380c8763a (patch)
tree566eb99ae17fe212f556789b1b48e4f8e6e094ed
parent69e9c7e3b1ad9c601e7f3f1a1f80d5578bcfbfc9 (diff)
QQuickSelectionRectangle: ensure we start the selection where the drag started
We should start the selection in TableView at the position where the user started the drag, and not where the centroid at the time when the dragging gets active (which is an offset equal to the mousePressAndHoldInterval property in QStyleHints). Change-Id: Ibe330d31c1e2c8022006a56b7119b1dcb3e0e5b9 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 6d2d4914f884fc1a88382ba5cb6eeeeab272874e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickselectionrectangle.cpp7
-rw-r--r--tests/auto/quickcontrols2/controls/data/tst_selectionrectangle.qml2
2 files changed, 5 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquickselectionrectangle.cpp b/src/quicktemplates2/qquickselectionrectangle.cpp
index 69eda47f9b..37e60e0c2c 100644
--- a/src/quicktemplates2/qquickselectionrectangle.cpp
+++ b/src/quicktemplates2/qquickselectionrectangle.cpp
@@ -210,11 +210,12 @@ QQuickSelectionRectanglePrivate::QQuickSelectionRectanglePrivate()
});
QObject::connect(m_dragHandler, &QQuickDragHandler::activeChanged, [this]() {
- const QPointF pos = m_dragHandler->centroid().position();
+ const QPointF startPos = m_dragHandler->centroid().pressPosition();
+ const QPointF dragPos = m_dragHandler->centroid().position();
if (m_dragHandler->active()) {
m_selectable->clearSelection();
- m_selectable->setSelectionStartPos(pos);
- m_selectable->setSelectionEndPos(pos);
+ m_selectable->setSelectionStartPos(startPos);
+ m_selectable->setSelectionEndPos(dragPos);
m_draggedHandle = nullptr;
updateHandles();
updateActiveState(true);
diff --git a/tests/auto/quickcontrols2/controls/data/tst_selectionrectangle.qml b/tests/auto/quickcontrols2/controls/data/tst_selectionrectangle.qml
index 437e8ec7f2..210c6594cd 100644
--- a/tests/auto/quickcontrols2/controls/data/tst_selectionrectangle.qml
+++ b/tests/auto/quickcontrols2/controls/data/tst_selectionrectangle.qml
@@ -337,7 +337,7 @@ TestCase {
}
// Drag on the bottom right handle, so that the selection shrinks to cell 1, 1
- mouseDrag(tableView, cellWidth * 2, cellHeight * 2, -cellWidth / 2, -cellHeight / 2, Qt.LeftButton)
+ mouseDrag(tableView, (cellWidth * 3) - 1, (cellHeight * 3) - 1, -cellWidth, -cellHeight, Qt.LeftButton)
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 1)))
}