diff options
author | Ćukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com> | 2013-12-12 13:27:57 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-13 10:16:39 +0100 |
commit | d9b5e704591571618c592564dc19a95d5e80f2c6 (patch) | |
tree | 517be4349deb1614592600540b682ac557ae6dfd /src/gui | |
parent | 43f9bb9a800b7081a48aaa0817f9ce0d453732b9 (diff) |
Introduce a way of explicit selection of the platform theme
Introduce a way of explicit selection of the platform theme to be used,
either through a new environment variable - QT_QPA_PLATFORMTHEME, or by
the optional -platformtheme command line argument.
Task-number: QTBUG-30091
Change-Id: Ieaa96b52265c3e48d056af7e56e793d8531fd7b3
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index ae956aaa19..190a6ec1a3 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -888,7 +888,7 @@ QString QGuiApplication::platformName() *QGuiApplicationPrivate::platform_name : QString(); } -static void init_platform(const QString &pluginArgument, const QString &platformPluginPath, int &argc, char **argv) +static void init_platform(const QString &pluginArgument, const QString &platformPluginPath, const QString &platformThemeName, int &argc, char **argv) { // Split into platform name and arguments QStringList arguments = pluginArgument.split(QLatin1Char(':')); @@ -922,15 +922,21 @@ static void init_platform(const QString &pluginArgument, const QString &platform } // Create the platform theme: - // 1) Ask the platform integration for a list of names. - const QStringList themeNames = QGuiApplicationPrivate::platform_integration->themeNames(); + + // 1) Fetch the platform name from the environment if present. + QStringList themeNames; + if (!platformThemeName.isEmpty()) + themeNames.append(platformThemeName); + + // 2) Ask the platform integration for a list of names and try loading them. + themeNames += QGuiApplicationPrivate::platform_integration->themeNames(); foreach (const QString &themeName, themeNames) { QGuiApplicationPrivate::platform_theme = QPlatformThemeFactory::create(themeName, platformPluginPath); if (QGuiApplicationPrivate::platform_theme) break; } - // 2) If none found, look for a theme plugin. Theme plugins are located in the + // 3) If none found, look for a theme plugin. Theme plugins are located in the // same directory as platform plugins. if (!QGuiApplicationPrivate::platform_theme) { foreach (const QString &themeName, themeNames) { @@ -941,7 +947,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform // No error message; not having a theme plugin is allowed. } - // 3) Fall back on the built-in "null" platform theme. + // 4) Fall back on the built-in "null" platform theme. if (!QGuiApplicationPrivate::platform_theme) QGuiApplicationPrivate::platform_theme = new QPlatformTheme; @@ -1001,6 +1007,8 @@ void QGuiApplicationPrivate::createPlatformIntegration() platformName = platformNameEnv; } + QString platformThemeName = QString::fromLocal8Bit(qgetenv("QT_QPA_PLATFORMTHEME")); + // Get command line params int j = argc ? 1 : 0; @@ -1016,6 +1024,9 @@ void QGuiApplicationPrivate::createPlatformIntegration() } else if (arg == "-platform") { if (++i < argc) platformName = argv[i]; + } else if (arg == "-platformtheme") { + if (++i < argc) + platformThemeName = QString::fromLocal8Bit(argv[i]); } else if (arg == "-qwindowgeometry" || (platformName == "xcb" && arg == "-geometry")) { if (++i < argc) windowGeometrySpecification = QWindowGeometrySpecification::fromArgument(argv[i]); @@ -1029,7 +1040,7 @@ void QGuiApplicationPrivate::createPlatformIntegration() argc = j; } - init_platform(QLatin1String(platformName), platformPluginPath, argc, argv); + init_platform(QLatin1String(platformName), platformPluginPath, platformThemeName, argc, argv); } |