From 0a7cd338e457eab691e22c2a00af8711018445d7 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Tue, 31 Dec 2024 18:55:50 -0500 Subject: [PATCH] Fix image sometimes scrolling by 1px when clicking inside viewport The max rounding error is +-0.5 so sometimes the rounding error alone caused a movement even if zero new change was requested. --- src/scrollhelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scrollhelper.cpp b/src/scrollhelper.cpp index 661a927d..c816fe6e 100644 --- a/src/scrollhelper.cpp +++ b/src/scrollhelper.cpp @@ -53,8 +53,8 @@ void ScrollHelper::move(QPointF delta) scrollDeltaY = calculateScrollDelta(scrollLocation.y(), vMin, vMax, scrollDeltaY); } scrollLocation += QPointF(scrollDeltaX, scrollDeltaY); - int scrollValueX = qRound(scrollLocation.x()); - int scrollValueY = qRound(scrollLocation.y()); + int scrollValueX = qAbs(scrollLocation.x()) == 0.5 ? 0 : qRound(scrollLocation.x()); + int scrollValueY = qAbs(scrollLocation.y()) == 0.5 ? 0 : qRound(scrollLocation.y()); lastMoveRoundingError = QPointF(scrollLocation.x() - scrollValueX, scrollLocation.y() - scrollValueY); int overscrollDistanceX = p.shouldConstrain && scrollValueX < hMin ? scrollValueX - hMin :