From ade2df4c4b2df638fefd42d9b755ee7a789da503 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 29 Jun 2022 07:53:29 +0200 Subject: Relayout QStaticText when dpi changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the cached font has a different DPI than the one used in QPainter, we need to treat this the same as if other font properties have changed and redo the layout. This happened when running the QStaticText test on Wayland, because the default dpi was 100 and the QPixmap we ended up drawing to was 96. This caused the pixel size of the font to be calculated differently when doing drawText() (using 96 dpi) and drawStaticText() (using the cached 100 dpi). Pick-to: 6.4 Fixes: QTBUG-100982 Change-Id: Ie4270341bb8a64b6458eb67ba460a282c65dc26b Reviewed-by: Tor Arne Vestbø --- src/gui/painting/qpainter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/gui/painting/qpainter.cpp') diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 6995f7d180..0ccfccb19e 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -39,6 +39,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -5448,7 +5449,9 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText QStaticTextPrivate *staticText_d = const_cast(QStaticTextPrivate::get(&staticText)); - if (font() != staticText_d->font) { + QFontPrivate *fp = QFontPrivate::get(font()); + QFontPrivate *stfp = QFontPrivate::get(staticText_d->font); + if (font() != staticText_d->font || fp == nullptr || stfp == nullptr || fp->dpi != stfp->dpi) { staticText_d->font = font(); staticText_d->needsRelayout = true; } -- cgit v1.2.3