|
6 | 6 | #include "qstyle.h" |
7 | 7 | #include "qstyleoption.h" |
8 | 8 | #include "qlabel_p.h" |
| 9 | +#include "private/qhexstring_p.h" |
9 | 10 | #include "private/qstylesheetstyle_p.h" |
10 | 11 | #include <qmath.h> |
11 | 12 |
|
@@ -1054,9 +1055,21 @@ void QLabel::paintEvent(QPaintEvent *) |
1054 | 1055 | const auto mode = isEnabled() ? QIcon::Normal : QIcon::Disabled; |
1055 | 1056 | QPixmap pix = d->icon->pixmap(size, dpr, mode); |
1056 | 1057 | if (d->scaledcontents && pix.size() != size * dpr) { |
1057 | | - pix = pix.scaled(size * dpr, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
1058 | | - pix.setDevicePixelRatio(dpr); |
1059 | | - d->icon->addPixmap(pix, mode); |
| 1058 | + const QString key = "qt_label_"_L1 % HexString<quint64>(pix.cacheKey()) |
| 1059 | + % HexString<quint8>(mode) |
| 1060 | + % HexString<uint>(size.width()) |
| 1061 | + % HexString<uint>(size.height()) |
| 1062 | + % HexString<quint16>(qRound(dpr * 1000)); |
| 1063 | + if (!QPixmapCache::find(key, &pix)) { |
| 1064 | + pix = pix.scaled(size * dpr, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); |
| 1065 | + pix.setDevicePixelRatio(dpr); |
| 1066 | + // using QIcon to cache the newly create pixmap is not possible |
| 1067 | + // because QIcon does not clear this cache (so we grow indefinitely) |
| 1068 | + // and also uses the newly added pixmap as starting point for new |
| 1069 | + // scaled pixmap which makes it very blurry. |
| 1070 | + // Therefore use QPixmapCache here. |
| 1071 | + QPixmapCache::insert(key, pix); |
| 1072 | + } |
1060 | 1073 | } |
1061 | 1074 | QStyleOption opt; |
1062 | 1075 | opt.initFrom(this); |
|
0 commit comments