summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <[email protected]>2024-01-10 14:21:52 +0100
committerQt Cherry-pick Bot <[email protected]>2024-01-22 18:53:18 +0000
commitf7add7ad0f7dc5538f2c2b752ba4aa9b29e1ec0a (patch)
treedb6e44b764487e2600f6c439ded5195425aa5629
parent3411f2984a5325a35e3bed1f961e5973d8a565b9 (diff)
Increase precision for QGraphicsView::AnchorUnderMouse
* Use a more precise view center for views with odd width/height * Use the QPointF version of mapToScene to avoid rounding * Round instead of truncate when setting scroll bar values These changes increase the precision of AnchorUnderMouse, which is important when for example wheel scrolling is used to change the scale of the view. Without these changes, the view shifts slightly with each change in the transform. [ChangeLog][QtWidgets][QGraphicsView] Increase precision for QGraphicsView::AnchorUnderMouse and QGraphicsView::centerOn Task-number: QTBUG-96879 Change-Id: I8199196c671e4aa96732f382e8057468f676b8d7 Reviewed-by: Eirik Aavitsland <[email protected]> (cherry picked from commit d99b0cfed21e05f6e84b97fe8edb68271a34deb2) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 4f1752a6b9072083ee8408c4cc7f3e821c9661a6)
-rw-r--r--src/widgets/graphicsview/qgraphicsview.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp
index fba6d942f81..76b5309ee8d 100644
--- a/src/widgets/graphicsview/qgraphicsview.cpp
+++ b/src/widgets/graphicsview/qgraphicsview.cpp
@@ -483,8 +483,8 @@ void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor)
if (q->underMouse()) {
// Last scene pos: lastMouseMoveScenePoint
// Current mouse pos:
- QPointF transformationDiff = q->mapToScene(viewport->rect().center())
- - q->mapToScene(viewport->mapFromGlobal(QCursor::pos()));
+ QPointF transformationDiff = mapToScene(viewport->rect().toRectF().center())
+ - mapToScene(viewport->mapFromGlobal(QCursor::pos().toPointF()));
q->centerOn(lastMouseMoveScenePoint + transformationDiff);
} else {
q->centerOn(lastCenterPoint);
@@ -504,8 +504,7 @@ void QGraphicsViewPrivate::centerView(QGraphicsView::ViewportAnchor anchor)
*/
void QGraphicsViewPrivate::updateLastCenterPoint()
{
- Q_Q(QGraphicsView);
- lastCenterPoint = q->mapToScene(viewport->rect().center());
+ lastCenterPoint = mapToScene(viewport->rect().toRectF().center());
}
/*!
@@ -1892,14 +1891,14 @@ void QGraphicsView::centerOn(const QPointF &pos)
qint64 horizontal = 0;
horizontal += horizontalScrollBar()->minimum();
horizontal += horizontalScrollBar()->maximum();
- horizontal -= int(viewPoint.x() - width / 2.0);
+ horizontal -= qRound(viewPoint.x() - width / 2.0);
horizontalScrollBar()->setValue(horizontal);
} else {
- horizontalScrollBar()->setValue(int(viewPoint.x() - width / 2.0));
+ horizontalScrollBar()->setValue(qRound(viewPoint.x() - width / 2.0));
}
}
if (!d->topIndent)
- verticalScrollBar()->setValue(int(viewPoint.y() - height / 2.0));
+ verticalScrollBar()->setValue(qRound(viewPoint.y() - height / 2.0));
d->lastCenterPoint = oldCenterPoint;
}