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 <axel.spoerl@qt.io>
(cherry picked from commit 74e8f673b827c57ebf2bf802840c19e4a1ac848b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-04-19 17:16:19 +02:00 committed by Qt Cherry-pick Bot
parent e0ee9cfe31
commit 15ce2b8b7a

View File

@ -755,17 +755,18 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
QRect r = opt->rect; QRect r = opt->rect;
int size = qMin(r.height(), r.width()); int size = qMin(r.height(), r.width());
QPixmap pixmap; QPixmap pixmap;
const qreal pixelRatio = p->device()->devicePixelRatio();
const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1 const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1
% QLatin1StringView(metaObject()->className()) % QLatin1StringView(metaObject()->className())
% HexString<uint>(pe), % HexString<uint>(pe),
opt, QSize(size, size)); opt, QSize(size, size) * pixelRatio);
if (!QPixmapCache::find(pixmapName, &pixmap)) { if (!QPixmapCache::find(pixmapName, &pixmap)) {
const qreal pixelRatio = p->device()->devicePixelRatio();
const qreal border = pixelRatio * (size / 5.); const qreal border = pixelRatio * (size / 5.);
const qreal sqsize = pixelRatio * size; const qreal sqsize = pixelRatio * size;
QImage image(sqsize, sqsize, QImage::Format_ARGB32_Premultiplied); QImage image(sqsize, sqsize, QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent); image.fill(Qt::transparent);
QPainter imagePainter(&image); QPainter imagePainter(&image);
imagePainter.setRenderHint(QPainter::Antialiasing);
QPolygonF poly; QPolygonF poly;
switch (pe) { switch (pe) {
@ -793,9 +794,9 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q
bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget); bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
} }
const QRectF bounds = poly.boundingRect(); const QPointF boundsCenter = poly.boundingRect().center();
const qreal sx = sqsize / 2 - bounds.center().x() - 1; const qreal sx = sqsize / 2 - boundsCenter.x();
const qreal sy = sqsize / 2 - bounds.center().y() - 1; const qreal sy = sqsize / 2 - boundsCenter.y();
imagePainter.translate(sx + bsx, sy + bsy); imagePainter.translate(sx + bsx, sy + bsy);
imagePainter.setPen(opt->palette.buttonText().color()); imagePainter.setPen(opt->palette.buttonText().color());
imagePainter.setBrush(opt->palette.buttonText()); imagePainter.setBrush(opt->palette.buttonText());