diff options
author | Zhang Hao <zhanghao@uniontech.com> | 2021-12-31 13:56:14 +0800 |
---|---|---|
committer | Zhang Hao <zhanghao@uniontech.com> | 2022-02-10 03:37:18 +0000 |
commit | bb67b6ff261bb24f99fa2b0e83a635e4f9f3e0c6 (patch) | |
tree | 94af126bb9e0d257ec092cb0234886c1eb32dc74 /src/widgets/itemviews | |
parent | ae7799a924c07f0f5de4e5c3321a87fe5bbafbb1 (diff) | |
download | qtbase-bb67b6ff261bb24f99fa2b0e83a635e4f9f3e0c6.tar.gz |
Always update pressedPosition when drag was enabled
Since e02293a76d21e7077f1952d4ed8af6c6d1970190 and
2e0c29a4bbe2b3ae427137e65f179b0550dcf169 was committed,
If a item width more than others,the selectionRect.x() always consist
of currentStartSelection item's rect.center().x(),this will cause
selectionRect size is not right.
Because the code of 2e0c29a4bbe2b3ae427137e65f179b0550dcf169 is to fix
the new bug introduced by e02293a76d21e7077f1952d4ed8af6c6d1970190,
we need to use a better way to solve QTBUG-78797.
When itemview enable drag,we need always update pressedPosition because
pressedPosition was used to determine the drag distance, otherwise keep
previous logic.
Fixes: QTBUG-78797
Fixes: QTBUG-81542
Fixes: QTBUG-99512
Pick-to: 6.2 6.3
Change-Id: Ibc5020e35b0eb319e4b5546bdba39ff527c209a6
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 21d0cf2e2c..16b5c26096 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1817,9 +1817,16 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); d->noSelectionOnMousePress = command == QItemSelectionModel::NoUpdate || !index.isValid(); QPoint offset = d->offset(); - d->pressedPosition = d->draggedPosition = pos + offset; - if (!(command & QItemSelectionModel::Current)) + d->draggedPosition = pos + offset; + + // update the pressed position when drag was enable + if (d->dragEnabled) + d->pressedPosition = d->draggedPosition; + + if (!(command & QItemSelectionModel::Current)) { + d->pressedPosition = pos + offset; d->currentSelectionStartIndex = index; + } else if (!d->currentSelectionStartIndex.isValid()) d->currentSelectionStartIndex = currentIndex(); @@ -1839,7 +1846,7 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) command |= d->ctrlDragSelectionFlag; } - if ((command & QItemSelectionModel::Current) == 0) { + if (!(command & QItemSelectionModel::Current)) { setSelection(QRect(pos, QSize(1, 1)), command); } else { QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos); @@ -1895,16 +1902,10 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) || edit(index, NoEditTriggers, event)) return; - if (d->selectionMode != SingleSelection) { - // Use the current selection start index if it is valid as this will be based on the - // start of the selection and not the last item being pressed which can be different - // when in extended selection - topLeft = d->currentSelectionStartIndex.isValid() - ? visualRect(d->currentSelectionStartIndex).center() - : d->pressedPosition - d->offset(); - } else { + if (d->selectionMode != SingleSelection) + topLeft = d->pressedPosition - d->offset(); + else topLeft = bottomRight; - } d->checkMouseMove(index); |