summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <[email protected]>2025-06-11 13:30:39 +0200
committerVolker Hilsheimer <[email protected]>2025-06-16 16:41:00 +0200
commit047806922c5d4442ce21df0bc2fdb3932e52a35f (patch)
treee2e3e6a4c69aa75ee57d9fa4bf62283583077ec0
parentfed6d715110e37eb3d0b646dedefc70699401a6f (diff)
QFontIconEngine: use the horizontalAdvance when calculating actualSize
Glyphs used for the icon might have left or right bearing, and we need to include those metrics in the calculation of the actual size of the icon so that QIcon correctly aligns it in the target rectangle when painting. Observed on Windows with the icon used for QIcon::ThemeIcon::DialogInformation; the glyph for \ue946 in the Segoe Fluent Icons font has a right bearing of 18.75, and the icon was rendered too far to the left, truncating pixels. Using the horizontalAdvance instead of the boundingRect includes those values. QFontMetrics doesn't have an API that give us the minimal rect that fits all pixels, or the actual height of a specific text, so use tightBoundingRect.height for the height. Fixes: QTBUG-136176 Fixes: QTBUG-134604 Pick-to: 6.10 6.9 Change-Id: I7c0065c625aa9b01f8eaf770ba13a0995f3df4de Reviewed-by: Eirik Aavitsland <[email protected]> Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
-rw-r--r--src/gui/image/qfonticonengine.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/gui/image/qfonticonengine.cpp b/src/gui/image/qfonticonengine.cpp
index dfbb2deb365..903d59727a1 100644
--- a/src/gui/image/qfonticonengine.cpp
+++ b/src/gui/image/qfonticonengine.cpp
@@ -76,7 +76,7 @@ QSize QFontIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::St
QSizeF result;
if (const QString text = string(); !text.isEmpty()) {
const QFontMetricsF fm(renderFont);
- result = fm.boundingRect(text).size();
+ result = {fm.horizontalAdvance(text), fm.tightBoundingRect(text).height()};
} else if (glyph_t glyphIndex = glyph()) {
QFontEngine *engine = QFontPrivate::get(renderFont)->engineForScript(QChar::Script_Common);