From dc7a2d20f85b4db8db09ec9a9b6369445926333a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 10 May 2023 18:46:22 +0200 Subject: [PATCH] Consult QIcon::fallbackThemeName() even when theme name is empty We still need to consult fallbackThemeName() when computing the parent list for an individual theme, as the Freedesktop Theme Icon spec mandates that the "hicolor" theme comes last, but we no longer need to do explicit fallback to fallbackThemeName() if a theme is not found. Change-Id: I6c0b5a45d8258c5b6eaa761402944a735b1606ba Reviewed-by: Axel Spoerl (cherry picked from commit addde7843f0bcbf7da8171e5146d8f1822ee0428) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qiconloader.cpp | 15 ++++++++------- tests/auto/gui/image/qicon/tst_qicon.cpp | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index a67d1439f87..3aa5fa5057b 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -442,9 +442,8 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, if (!theme.isValid()) { theme = QIconTheme(themeName); if (!theme.isValid()) { - qCDebug(lcIconLoader) << "Theme" << themeName << "not found;" - << "trying fallback theme" << fallbackThemeName(); - theme = QIconTheme(fallbackThemeName()); + qCDebug(lcIconLoader) << "Theme" << themeName << "not found"; + return info; } } @@ -586,10 +585,12 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const qCDebug(lcIconLoader) << "Loading icon" << name; QThemeIconInfo iconInfo; - if (!themeName().isEmpty()) { - QStringList visited; - iconInfo = findIconHelper(themeName(), name, visited); - } + QStringList visitedThemes; + if (!themeName().isEmpty()) + iconInfo = findIconHelper(themeName(), name, visitedThemes); + + if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty()) + iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes); if (iconInfo.entries.empty()) iconInfo = lookupFallbackIcon(name); diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 4ae908058ed..0d8213a6171 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -732,6 +732,10 @@ void tst_QIcon::fromTheme() // named system icon theme. QIcon::setThemeName(""); // Reset user-theme if (QIcon::themeName().isEmpty()) { + // Test icon from fallback theme even when theme name is empty + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + // Test icon from fallback path even when theme name is empty fallbackIcon = QIcon::fromTheme("red"); QVERIFY(!fallbackIcon.isNull());