diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-04-19 22:05:15 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-04-22 20:26:52 +0200 |
commit | f5fa811e882bdbb2e4d3c3c3f4df1553e8cf0f87 (patch) | |
tree | cde3e95fa9c9a40cadb8643a0e220fd3188274a4 | |
parent | 896c4fe4279f7dc761dcd59f7b0cde070c38b3cb (diff) |
QCommonStyle: don't use a QImage when drawing arrows
Using a QImage as a paintDevice is not needed - directly paint on a
QPixmap. Also use styleCachePixmap() which avoids the need for
multiplying the size with the dpr.
Change-Id: I114f78c20d2b92b4fd135c8f64b452fb81a02baf
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index b853a8e963..418a0c2c5f 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -750,22 +750,21 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q case PE_IndicatorArrowRight: case PE_IndicatorArrowLeft: { - if (opt->rect.width() <= 1 || opt->rect.height() <= 1) + const QRect &r = opt->rect; + if (r.width() <= 1 || r.height() <= 1) break; - QRect r = opt->rect; int size = qMin(r.height(), r.width()); QPixmap pixmap; - const qreal pixelRatio = p->device()->devicePixelRatio(); + const qreal dpr = p->device()->devicePixelRatio(); const QString pixmapName = QStyleHelper::uniqueName("$qt_ia-"_L1 % QLatin1StringView(metaObject()->className()) % HexString<uint>(pe), - opt, QSize(size, size), pixelRatio); + opt, QSize(size, size), dpr); if (!QPixmapCache::find(pixmapName, &pixmap)) { - 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); + const qreal border = size / 5.; + const qreal sqsize = size; + pixmap = styleCachePixmap(QSize(size, size), dpr); + QPainter imagePainter(&pixmap); imagePainter.setRenderHint(QPainter::Antialiasing); QPolygonF poly; @@ -813,8 +812,6 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q imagePainter.drawPolygon(poly); imagePainter.end(); - pixmap = QPixmap::fromImage(image); - pixmap.setDevicePixelRatio(pixelRatio); QPixmapCache::insert(pixmapName, pixmap); } int xOffset = r.x() + (r.width() - size)/2; |