diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2023-12-14 13:54:05 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-01-12 12:59:26 +0100 |
commit | c53b91cc12164d779a69c2526d85e3ab9c2841e2 (patch) | |
tree | 7086b40556508feffefdb6fdbf17a1df33417a7d /src/gui/image | |
parent | 742be5254c9919e8c743b8b489c054d778ee4850 (diff) |
QIcon::availableSizes(): don't return duplicates
QIcon::availableSizes() returned duplicate sizes when there are pixmaps
with a different dpi but same size. This is not useful and therefore
filter them out. Also rearrange the conditions a little bit to bail out
on wrong mode/state early.
Pick-to: 6.7
Task-number: QTBUG-119915
Change-Id: I9d18c78fc2a149a3a9eaaed67c6110979029705b
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qicon.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 35f6cad4e2..8176f40222 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -351,15 +351,16 @@ QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon:: QList<QSize> QPixmapIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state) { QList<QSize> sizes; - for (int i = 0; i < pixmaps.size(); ++i) { - QPixmapIconEngineEntry &pe = pixmaps[i]; - if (pe.size == QSize() && pe.pixmap.isNull()) { + for (QPixmapIconEngineEntry &pe : pixmaps) { + if (pe.mode != mode || pe.state != state) + continue; + if (pe.size.isEmpty() && pe.pixmap.isNull()) { pe.pixmap = QPixmap(pe.fileName); pe.size = pe.pixmap.size(); } - if (pe.mode == mode && pe.state == state && !pe.size.isEmpty()) + if (!pe.size.isEmpty() && !sizes.contains(pe.size)) sizes.push_back(pe.size); - } + } return sizes; } |