diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 1581ce5a797..3ebdd6ec23c 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1233,6 +1233,10 @@ QString QIcon::fallbackThemeName() Sets the fallback icon theme to \a name. + The fallback icon theme is used for last resort lookup of icons + not provided by the \l{themeName()}{current icon theme}, + or if the \l{themeName()}{current icon theme} does not exist. + The \a name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing its contents. diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 10d5f65b805..2e3097ce56b 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -394,21 +394,27 @@ QIconTheme::QIconTheme(const QString &themeName) // Parent themes provide fallbacks for missing icons m_parents = indexReader.value("Icon Theme/Inherits"_L1).toStringList(); m_parents.removeAll(QString()); - - // Ensure a default platform fallback for all themes - if (m_parents.isEmpty()) { - const QString fallback = QIconLoader::instance()->fallbackThemeName(); - if (!fallback.isEmpty()) - m_parents.append(fallback); - } - - // Ensure that all themes fall back to hicolor - if (!m_parents.contains("hicolor"_L1)) - m_parents.append("hicolor"_L1); } #endif // settings } +QStringList QIconTheme::parents() const +{ + // Respect explicitly declared parents + QStringList result = m_parents; + + // Ensure a default fallback for all themes + const QString fallback = QIconLoader::instance()->fallbackThemeName(); + if (!fallback.isEmpty()) + result.append(fallback); + + // Ensure that all themes fall back to hicolor + if (!result.contains("hicolor"_L1)) + result.append("hicolor"_L1); + + return result; +} + QDebug operator<<(QDebug debug, const std::unique_ptr &entry) { QDebugStateSaver saver(debug); diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index 0b67dcdbad5..816fb7708cd 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -145,7 +145,7 @@ class QIconTheme public: QIconTheme(const QString &name); QIconTheme() : m_valid(false) {} - QStringList parents() { return m_parents; } + QStringList parents() const; QList keyList() { return m_keyList; } QStringList contentDirs() { return m_contentDirs; } bool isValid() { return m_valid; } diff --git a/tests/auto/gui/image/qicon/CMakeLists.txt b/tests/auto/gui/image/qicon/CMakeLists.txt index 2d212defb78..ce9528ae45e 100644 --- a/tests/auto/gui/image/qicon/CMakeLists.txt +++ b/tests/auto/gui/image/qicon/CMakeLists.txt @@ -58,6 +58,8 @@ set(tst_qicon_resource_files "./icons/themeparent/scalable/actions/appointment-new.svg" "./icons/fallbacktheme/index.theme" "./icons/fallbacktheme/16x16/edit-cut.png" + "./icons/hicolor/index.theme" + "./icons/hicolor/16x16/hicolor-icon.png" "./second_icons/testtheme/32x32/actions/appointment-new.png" "./styles/commonstyle/images/standardbutton-open-128.png" "./styles/commonstyle/images/standardbutton-open-16.png" diff --git a/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png new file mode 100644 index 00000000000..661ef1ad030 Binary files /dev/null and b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png differ diff --git a/tests/auto/gui/image/qicon/icons/hicolor/index.theme b/tests/auto/gui/image/qicon/icons/hicolor/index.theme new file mode 100644 index 00000000000..e5e5cef9b1e --- /dev/null +++ b/tests/auto/gui/image/qicon/icons/hicolor/index.theme @@ -0,0 +1,11 @@ +[Icon Theme] +Name=hicolor + +# Provide a minimal hicolor theme, so that our hicolor fallback +# lookup during testing will find that theme on all systems. + +Directories=16x16 + +[16x16] +Size=16 +Type=Fixed diff --git a/tests/auto/gui/image/qicon/icons/testtheme/index.theme b/tests/auto/gui/image/qicon/icons/testtheme/index.theme index e18736ab43c..53664b14b2c 100644 --- a/tests/auto/gui/image/qicon/icons/testtheme/index.theme +++ b/tests/auto/gui/image/qicon/icons/testtheme/index.theme @@ -1,7 +1,7 @@ [Icon Theme] _Name=Test _Comment=Test Theme -Inherits=crystalsvg, themeparent +Inherits=themeparent Example=x-directory-normal # KDE Specific Stuff diff --git a/tests/auto/gui/image/qicon/icons/themeparent/index.theme b/tests/auto/gui/image/qicon/icons/themeparent/index.theme index e536a0bf2f2..96267addd6a 100644 --- a/tests/auto/gui/image/qicon/icons/themeparent/index.theme +++ b/tests/auto/gui/image/qicon/icons/themeparent/index.theme @@ -1,7 +1,6 @@ [Icon Theme] _Name=Test _Comment=Test Theme -Inherits=gnome,crystalsvg Example=x-directory-normal # KDE Specific Stuff