[frameworks/kirigami] src/primitives: Icon: snap the aspect-preserving painted size to device pixels

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit cbb2deb77e0a3da2d462a7581a1c4a2a482570ff by Méven Car.
Committed on 20/07/2026 at 11:08.
Pushed by meven into branch 'master'.

Icon: snap the aspect-preserving painted size to device pixels

In the roundToIconSize path the icon size is derived from roundedWidth, which
is snapped to whole device pixels so the icon stays crisp at fractional device
pixel ratios. The branch that keeps the source aspect ratio computes its size
directly from the item and source dimensions with no such snapping, so a scaled
image could land on a fractional device pixel and look slightly soft. Snap the
resulting size to whole device pixels.

M  +3    -0    src/primitives/icon.cpp

https://invent.kde.org/frameworks/kirigami/-/commit/cbb2deb77e0a3da2d462a7581a1c4a2a482570ff

diff --git a/src/primitives/icon.cpp b/src/primitives/icon.cpp
index 645bb3e9f..7f3239b4a 100644
--- a/src/primitives/icon.cpp
+++ b/src/primitives/icon.cpp
@@ -627,6 +627,9 @@ void Icon::updatePaintedGeometry()
             } else if (heightScale < widthScale) {
                 newSize = QSizeF(heightScale * iconPixSize.width(), h);
             }
+            // Snap to whole device pixels so the texture stays crisp at fractional DPR.
+            newSize = QSizeF(std::round(newSize.width() * m_devicePixelRatio) / m_devicePixelRatio,
+                             std::round(newSize.height() * m_devicePixelRatio) / m_devicePixelRatio);
         }
     }
     if (newSize != m_paintedSize) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.