Skip to content

Commit

Permalink
QCommonStyle: don't use a QImage when drawing arrows
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chehrlic committed Apr 22, 2024
1 parent 896c4fe commit f5fa811
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/widgets/styles/qcommonstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f5fa811

Please sign in to comment.