aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2022-12-02 17:30:26 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-12-08 09:22:19 +0000
commita3759ce6aa208a7b59d7f22247935c17c5fb9ad3 (patch)
tree3b16d60c5d906a84815cc44fa2f09bd447261c74
parentc47ffb5d91975f22e4da272ab837c0f8793feb46 (diff)
Stabilize rendering of Rectangle borders under fractional scaling
By default, border widths are rounded to integer values (in QSGBasicInternalRectangleNode::updateGeometry()), so one avoids artifacts where the rendered width can fluctuate with one pixel if the Rectangle coordinates are fractional. However, that rounding was done before the device pixel ratio scaling, so if the dpr was fractional, one would get a fractional rendered border width, and hence fluctuations. Fix by taking the dpr into account. The rounding is done in the Item, where the dpr is known, instead of the SG Node. Fixes: QTBUG-108831 Change-Id: I9a1d8180c72dd5e1b1eaa9f1c420eb9944f1e5a5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 73a3b69f9ae6d49cc04ce9834ab6f3b88d11e35b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickrectangle.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp
index fbefe1fa06..c69f7e5957 100644
--- a/src/quick/items/qquickrectangle.cpp
+++ b/src/quick/items/qquickrectangle.cpp
@@ -578,8 +578,13 @@ QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
if (d->pen && d->pen->isValid()) {
rectangle->setPenColor(d->pen->color());
- rectangle->setPenWidth(d->pen->width());
- rectangle->setAligned(d->pen->pixelAligned());
+ qreal penWidth = d->pen->width();
+ if (d->pen->pixelAligned()) {
+ qreal dpr = window() ? window()->effectiveDevicePixelRatio() : 1.0;
+ penWidth = qRound(penWidth * dpr) / dpr; // Ensures integer width after dpr scaling
+ }
+ rectangle->setPenWidth(penWidth);
+ rectangle->setAligned(false); // width rounding already done, so the Node should not do it
} else {
rectangle->setPenWidth(0);
}