summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-07-11 01:44:33 -0700
committerJake Petroules <jake.petroules@qt.io>2017-11-21 03:10:42 +0000
commitdf47fdb8563452a1e68d4ec6d7c6eb36e7a9d353 (patch)
treedf1807c1af1e32d3c2b64dc26cf7a90cdf60e328
parenta6d21e484a4d0f3308dbdb157e602ab5965bccf3 (diff)
downloadqtquickcontrols-df47fdb8563452a1e68d4ec6d7c6eb36e7a9d353.tar.gz
Pick the default style name at runtime instead of compile time
Instead of a naïve OS-based compile time check, we check which platform plugin is in use at runtime. This should give a more accurate mapping, especially on desktop OSes using alternative platform plugins where the Desktop style is not useful. The minimum Android SDK version is 16 now, so the check is removed. Change-Id: Ie7af3a8ce5fd031256f5eba9706f24ab50a23bf9 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
-rw-r--r--src/controls/Private/qquickcontrolsettings.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp
index d8cfdaed..95c656b2 100644
--- a/src/controls/Private/qquickcontrolsettings.cpp
+++ b/src/controls/Private/qquickcontrolsettings.cpp
@@ -58,19 +58,31 @@ QT_BEGIN_NAMESPACE
static QString defaultStyleName()
{
- //Only enable QStyle support when we are using QApplication
-#if defined(QT_WIDGETS_LIB) && !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_QNX) && !defined(Q_OS_WINRT)
- if (QCoreApplication::instance()->inherits("QApplication"))
- return QLatin1String("Desktop");
-#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
- if (QtAndroidPrivate::androidSdkVersion() >= 11)
- return QLatin1String("Android");
-#elif defined(Q_OS_IOS)
- return QLatin1String("iOS");
-#elif defined(Q_OS_WINRT) && 0 // Enable once style is ready
- return QLatin1String("WinRT");
+ static const QMap<QString, QString> styleMap {
+#if defined(QT_WIDGETS_LIB)
+ {QLatin1String("cocoa"), QLatin1String("Desktop")},
+ {QLatin1String("wayland"), QLatin1String("Desktop")},
+ {QLatin1String("windows"), QLatin1String("Desktop")},
+ {QLatin1String("xcb"), QLatin1String("Desktop")},
#endif
- return QLatin1String("Base");
+ {QLatin1String("android"), QLatin1String("Android")},
+ {QLatin1String("ios"), QLatin1String("iOS")},
+#if 0 // Enable once style is ready
+ {QLatin1String("winrt"), QLatin1String("WinRT")},
+#endif
+ };
+
+ QGuiApplication *app = static_cast<QGuiApplication *>(
+ QCoreApplication::instance());
+ const QString styleName = styleMap.value(app->platformName(), QLatin1String("Base"));
+
+#if defined(QT_WIDGETS_LIB)
+ // Only enable QStyle support when we are using QApplication
+ if (styleName == QLatin1String("Desktop") && !app->inherits("QApplication"))
+ return QLatin1String("Base");
+#endif
+
+ return styleName;
}
static QString styleEnvironmentVariable()