From 15ce2b8b7aa74f8e867998ef4303d115d359b6aa Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 19 Apr 2024 17:16:19 +0200 Subject: [PATCH] QCommonStyle: paint arrows with anti-aliasing The high-dpi painting fix for the arrow painting was missing QPainter::AntiAliasing flag so the rectangle had some artifacts with certain (small) sizes. Also there is no reason to move the center by 1 pixel to the top left anymore now that we're using decimal values. This amends 3936d254ca0e7259cd97238c31df8413d03fd475. Fixes: QTBUG-124554 Task-number: QTBUG-114539 Change-Id: I8a34d7ed937db261ce652bd66234783fb3338cbb Reviewed-by: Axel Spoerl (cherry picked from commit 74e8f673b827c57ebf2bf802840c19e4a1ac848b) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qcommonstyle.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index ee27e00e4d6..958da27825c 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -755,17 +755,18 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q QRect r = opt->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; + const qreal pixelRatio = p->device()->devicePixelRatio(); const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1 % QLatin1StringView(metaObject()->className()) % HexString(pe), - opt, QSize(size, size)); + opt, QSize(size, size) * pixelRatio); if (!QPixmapCache::find(pixmapName, &pixmap)) { - const qreal pixelRatio = p->device()->devicePixelRatio(); const qreal border = pixelRatio * (size / 5.); const qreal sqsize = pixelRatio * size; QImage image(sqsize, sqsize, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter imagePainter(&image); + imagePainter.setRenderHint(QPainter::Antialiasing); QPolygonF poly; switch (pe) { @@ -793,9 +794,9 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget); } - const QRectF bounds = poly.boundingRect(); - const qreal sx = sqsize / 2 - bounds.center().x() - 1; - const qreal sy = sqsize / 2 - bounds.center().y() - 1; + const QPointF boundsCenter = poly.boundingRect().center(); + const qreal sx = sqsize / 2 - boundsCenter.x(); + const qreal sy = sqsize / 2 - boundsCenter.y(); imagePainter.translate(sx + bsx, sy + bsy); imagePainter.setPen(opt->palette.buttonText().color()); imagePainter.setBrush(opt->palette.buttonText());