diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 3ebdd6ec23..7911f126a0 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1156,6 +1156,11 @@ QStringList QIcon::themeSearchPaths() Returns the fallback search paths for icons. + The fallback search paths are used to look for standalone + icon files if the \l{themeName()}{current icon theme} + or \l{fallbackIconTheme()}{fallback icon theme} do + not provide results for an icon lookup. + The default value will depend on the platform. \sa setFallbackSearchPaths(), themeSearchPaths() @@ -1170,6 +1175,11 @@ QStringList QIcon::fallbackSearchPaths() Sets the fallback search paths for icons to \a paths. + The fallback search paths are used to look for standalone + icon files if the \l{themeName()}{current icon theme} + or \l{fallbackIconTheme()}{fallback icon theme} do + not provide results for an icon lookup. + \note To add some path without replacing existing ones: \snippet code/src_gui_image_qicon.cpp 5 diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 2e3097ce56..6c5621000e 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -585,10 +585,11 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const if (!themeName().isEmpty()) { QStringList visited; iconInfo = findIconHelper(themeName(), name, visited); - if (iconInfo.entries.empty()) - iconInfo = lookupFallbackIcon(name); } + if (iconInfo.entries.empty()) + iconInfo = lookupFallbackIcon(name); + qCDebug(lcIconLoader) << "Resulting icon entries" << iconInfo.entries; return iconInfo; } diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 4b10449068..4ae908058e 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -727,6 +727,18 @@ void tst_QIcon::fromTheme() abIcon = QIcon::fromTheme("address-book-new"); QVERIFY(abIcon.isNull()); + // Test fallback icon behavior for empty theme names. + // Can only reliably test this on systems that don't have a + // named system icon theme. + QIcon::setThemeName(""); // Reset user-theme + if (QIcon::themeName().isEmpty()) { + // Test icon from fallback path even when theme name is empty + fallbackIcon = QIcon::fromTheme("red"); + QVERIFY(!fallbackIcon.isNull()); + QVERIFY(QIcon::hasThemeIcon("red")); + QCOMPARE(fallbackIcon.availableSizes().size(), 1); + } + // Passing a full path to fromTheme is not very useful, but should work anyway QIcon fullPathIcon = QIcon::fromTheme(m_pngImageFileName); QVERIFY(!fullPathIcon.isNull());