From 43c220149fd6a373d02a147407b44413313cd3b2 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 14 Dec 2023 13:54:05 +0100 Subject: [PATCH] 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. Task-number: QTBUG-119915 Change-Id: I9d18c78fc2a149a3a9eaaed67c6110979029705b Reviewed-by: Axel Spoerl (cherry picked from commit c53b91cc12164d779a69c2526d85e3ab9c2841e2) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qicon.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 41f9e7541ef..dc65c3897ec 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -348,15 +348,16 @@ QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon:: QList QPixmapIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state) { QList 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; }