diff options
author | Miika Pernu <[email protected]> | 2025-06-17 15:36:35 +0900 |
---|---|---|
committer | Volker Hilsheimer <[email protected]> | 2025-06-20 11:44:06 +0000 |
commit | 882a4df4fdd2a5952a605ca783142f46d9a92d5b (patch) | |
tree | 99579244d42ff74f9067e6c821c7147c4f92e84d | |
parent | 3183b7b79126551fe8528a6fbcf6e90830ee695a (diff) |
QAbstractItemView: fix autoscroll immediately stopping
Adjust the draggedPosition calculation to changes in
QAbstractItemViewPrivate::offset(). The draggedPosition was previously
first calculated by adding mouse pos and offset() value, and mouse pos
was later extracted by subtracting the offset() from draggedPosition.
However, the offset() value no longer remains a constant between the
addition and subtraction, which makes it impossible to get the old
mouse position.
Store the offset and mouse position separately to make the
calculations deterministic across events.
Fixes: QTBUG-130978
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I5c601ff7ca40c9d8fb7ad949ff15520d199f5c1f
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 17 | ||||
-rw-r--r-- | src/widgets/itemviews/qabstractitemview_p.h | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index e84ea0a8b7b..d06d9ce236d 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1812,12 +1812,13 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid(); QPoint offset = d->offset(); - d->draggedPosition = pos + offset; + d->draggedPosition = pos; + d->draggedPositionOffset = offset; #if QT_CONFIG(draganddrop) // update the pressed position when drag was enable if (d->dragEnabled) - d->pressedPosition = d->draggedPosition; + d->pressedPosition = d->draggedPosition + d->draggedPositionOffset; #endif if (!(command & QItemSelectionModel::Current)) { @@ -1874,7 +1875,8 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) Q_D(QAbstractItemView); QPoint bottomRight = event->position().toPoint(); - d->draggedPosition = bottomRight + d->offset(); + d->draggedPosition = bottomRight; + d->draggedPositionOffset = d->offset(); if (state() == ExpandingState || state() == CollapsingState) return; @@ -2049,7 +2051,8 @@ void QAbstractItemView::dragEnterEvent(QDragEnterEvent *event) void QAbstractItemView::dragMoveEvent(QDragMoveEvent *event) { Q_D(QAbstractItemView); - d->draggedPosition = event->position().toPoint() + d->offset(); + d->draggedPosition = event->position().toPoint(); + d->draggedPositionOffset = d->offset(); if (dragDropMode() == InternalMove && (event->source() != this || !(event->possibleActions() & Qt::MoveAction))) return; @@ -4090,7 +4093,8 @@ void QAbstractItemView::doAutoScroll() const int verticalValue = verticalScroll->value(); const int horizontalValue = horizontalScroll->value(); - const QPoint pos = d->draggedPosition - d->offset(); + const QPoint pos = d->draggedPosition; + const QRect area = QWidgetPrivate::get(d->viewport)->clipRect(); // do the scrolling if we are in the scroll margins @@ -4130,7 +4134,8 @@ void QAbstractItemView::doAutoScroll() // update our dragged position manually after the scroll. "pos" is the old // draggedPosition - d->offset(), and d->offset() is now updated after scrolling, so // pos + d->offset() gives us the new position. - d->draggedPosition = pos + d->offset(); + d->draggedPosition = pos; + d->draggedPositionOffset = d->offset(); break; } default: diff --git a/src/widgets/itemviews/qabstractitemview_p.h b/src/widgets/itemviews/qabstractitemview_p.h index df8233ea047..60f0284d76a 100644 --- a/src/widgets/itemviews/qabstractitemview_p.h +++ b/src/widgets/itemviews/qabstractitemview_p.h @@ -351,6 +351,7 @@ public: Qt::KeyboardModifiers pressedModifiers; QPoint pressedPosition; QPoint draggedPosition; + QPoint draggedPositionOffset; bool pressedAlreadySelected; bool releaseFromDoubleClick; |