From 62f32c7e18387ab3bd50bfa91b37c7f22be0f6e9 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 11 Nov 2023 21:14:54 +0100 Subject: [PATCH] QCommonStyle: Adjust painting arrows in high-dpi mode PE_IndicatorArrowUp/Down/Left/Right was drawn using integer coordinates for the three edges which lead to artifacts in high-dpi mode. Fix it by using QPointF instead. Fixes: QTBUG-114539 Change-Id: I03cbff2ef789e8cee0f3a0d84138d94516340669 Reviewed-by: Volker Hilsheimer (cherry picked from commit 3936d254ca0e7259cd97238c31df8413d03fd475) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qcommonstyle.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index b247cf6f67f..b32198c5e6f 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -741,26 +741,26 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q % HexString(pe), opt, QSize(size, size)); if (!QPixmapCache::find(pixmapName, &pixmap)) { - qreal pixelRatio = p->device()->devicePixelRatio(); - int border = qRound(pixelRatio*(size/5)); - int sqsize = qRound(pixelRatio*(2*(size/2))); + 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(0); + image.fill(Qt::transparent); QPainter imagePainter(&image); - QPolygon a; + QPolygonF poly; switch (pe) { case PE_IndicatorArrowUp: - a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); + poly = {QPointF(border, sqsize / 2), QPointF(sqsize / 2, border), QPointF(sqsize - border, sqsize / 2)}; break; case PE_IndicatorArrowDown: - a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); + poly = {QPointF(border, sqsize / 2), QPointF(sqsize / 2, sqsize - border), QPointF(sqsize - border, sqsize / 2)}; break; case PE_IndicatorArrowRight: - a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + poly = {QPointF(sqsize - border, sqsize / 2), QPointF(sqsize / 2, border), QPointF(sqsize / 2, sqsize - border)}; break; case PE_IndicatorArrowLeft: - a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); + poly = {QPointF(border, sqsize / 2), QPointF(sqsize / 2, border), QPointF(sqsize / 2, sqsize - border)}; break; default: break; @@ -774,9 +774,9 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget); } - QRect bounds = a.boundingRect(); - int sx = sqsize / 2 - bounds.center().x() - 1; - int sy = sqsize / 2 - bounds.center().y() - 1; + const QRectF bounds = poly.boundingRect(); + const qreal sx = sqsize / 2 - bounds.center().x() - 1; + const qreal sy = sqsize / 2 - bounds.center().y() - 1; imagePainter.translate(sx + bsx, sy + bsy); imagePainter.setPen(opt->palette.buttonText().color()); imagePainter.setBrush(opt->palette.buttonText()); @@ -785,13 +785,13 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q imagePainter.translate(1, 1); imagePainter.setBrush(opt->palette.light().color()); imagePainter.setPen(opt->palette.light().color()); - imagePainter.drawPolygon(a); + imagePainter.drawPolygon(poly); imagePainter.translate(-1, -1); imagePainter.setBrush(opt->palette.mid().color()); imagePainter.setPen(opt->palette.mid().color()); } - imagePainter.drawPolygon(a); + imagePainter.drawPolygon(poly); imagePainter.end(); pixmap = QPixmap::fromImage(image); pixmap.setDevicePixelRatio(pixelRatio);