diff options
author | Axel Spoerl <[email protected]> | 2025-03-18 08:29:47 +0100 |
---|---|---|
committer | Axel Spoerl <[email protected]> | 2025-03-28 16:43:06 +0100 |
commit | 8ede178fd3427233ce368a2f69363a30a9468215 (patch) | |
tree | e8d0491df803713e0c0eebff414d0cf34e74ea2d | |
parent | 92860503ce3aeee98c5793d5d8915534e9fd4f1d (diff) |
Refactor and fix platform theme selection
Finding a platform theme for the list of theme names happened in two
separate loops. The first loop checked for a platform theme plugin, the
second for a platform integration plugin. In case a theme name was
passed from the environment (with the -platformtheme command line
argument or by setting QT_QPA_PLATFORMTHEME), it was ignored if it was
a platform integration plugin and a platform theme plugin was found
in the first loop.
Combine both loops, in the assumption that the list of theme names
is always correctly prioritized.
Pick-to: 6.9 6.8 6.5
Fixes: QTBUG-134702
Change-Id: I2703236dc0f406aeb48529f8e53de76c394b7172
Reviewed-by: Tor Arne Vestbø <[email protected]>
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 0d4a5dd7d69..0ed73c18362 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1349,10 +1349,10 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString // Create the platform theme: - // 1) Fetch the platform name from the environment if present. + // 1) Try the platform name from the environment if present QStringList themeNames; if (!platformThemeName.isEmpty()) { - qCDebug(lcQpaTheme) << "Adding" << platformThemeName << "from environment to list of theme names"; + qCDebug(lcQpaTheme) << "Adding" << platformThemeName << "from environment"; themeNames.append(platformThemeName); } @@ -1365,32 +1365,25 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString // 3) Ask the platform integration for a list of theme names const auto platformIntegrationThemeNames = QGuiApplicationPrivate::platform_integration->themeNames(); qCDebug(lcQpaTheme) << "Adding platform integration's theme names to list of theme names:" << platformIntegrationThemeNames; - themeNames += platformIntegrationThemeNames; + themeNames.append(platformIntegrationThemeNames); + // 4) Look for a theme plugin. for (const QString &themeName : std::as_const(themeNames)) { qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via QPlatformThemeFactory::create"; QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath); if (QGuiApplicationPrivate::platform_theme) { - qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName; + qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName << "via QPlatformThemeFactory::create"; break; } - } - - // 5) If no theme plugin was found ask the platform integration to - // create a theme - if (!QGuiApplicationPrivate::platform_theme) { - for (const QString &themeName : std::as_const(themeNames)) { - qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via createPlatformTheme"; - QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName); - if (QGuiApplicationPrivate::platform_theme) { - qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName; - break; - } + qCDebug(lcQpaTheme) << "Attempting to create platform theme" << themeName << "via createPlatformTheme"; + QGuiApplicationPrivate::platform_theme = QGuiApplicationPrivate::platform_integration->createPlatformTheme(themeName); + if (QGuiApplicationPrivate::platform_theme) { + qCDebug(lcQpaTheme) << "Successfully created platform theme" << themeName << "via createPlatformTheme"; + break; } - // No error message; not having a theme plugin is allowed. } - // 6) Fall back on the built-in "null" platform theme. + // 5) Fall back on the built-in "null" platform theme. if (!QGuiApplicationPrivate::platform_theme) { qCDebug(lcQpaTheme) << "Failed to create platform theme; using \"null\" platform theme"; QGuiApplicationPrivate::platform_theme = new QPlatformTheme; |