From 94d98bdb6326e784b8397044d50226daaefd6cce Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 11 Nov 2016 14:42:33 +0100 Subject: Add support for a QT_QUICK_CONTROLS_STYLE_PATH environment variable [ChangeLog][Controls][Styles] Added support for a QT_QUICK_CONTROLS_STYLE_PATH environment variable, which can be used to specify lookup paths for Qt Quick Controls 2 styles. This allows device manufacturers and Linux distributions to specify a system-wide style installation folder that may be located outside the Qt installation tree. Change-Id: Ic004d693bf6206971da6319d0cc13061b8fd1566 Reviewed-by: Mitch Curtis --- .../controls/doc/src/qtquickcontrols2-environment.qdoc | 6 ++++++ src/quickcontrols2/qquickstyle.cpp | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc index c83adf4b..93ab0bbb 100644 --- a/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc +++ b/src/imports/controls/doc/src/qtquickcontrols2-environment.qdoc @@ -46,6 +46,12 @@ \li \c QT_QUICK_CONTROLS_FALLBACK_STYLE \li Specifies a fallback style for \l {Creating a Custom Style}{custom styles}. The value can be one of the built-in styles, for example \c "Material", + \row + \li \c QT_QUICK_CONTROLS_STYLE_PATH + \li Specifies a list of additional paths that are used to lookup \l {Styling Qt Quick Controls 2} + {Qt Quick Controls 2 styles}. Multiple path entries must be \l {QDir::listSeparator}{separated} + by \c ':' under Unix and \c ';' under Windows. By default, styles are looked up from + \c $QML2_IMPORT_PATH/QtQuick/Controls.2. \row \li \c QT_QUICK_CONTROLS_CONF \li Specifies the location of the \l {Qt Quick Controls 2 configuration file}. diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index c8a3f19a..4247b204 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -182,6 +182,7 @@ struct QQuickStyleSpec for (const QString &path : stylePaths) { QString stylePath = findStyle(path, style); if (!stylePath.isEmpty()) { + custom = !stylePath.startsWith(baseUrl.toLocalFile()); style = stylePath; resolved = true; break; @@ -212,15 +213,22 @@ Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) QStringList QQuickStylePrivate::stylePaths() { + // system/custom style paths + QStringList paths; + if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE_PATH"))) { + const QByteArray value = qgetenv("QT_QUICK_CONTROLS_STYLE_PATH"); + paths += QString::fromLatin1(value).split(QDir::listSeparator(), QString::SkipEmptyParts); + } + + // built-in import paths const QString targetPath = QStringLiteral("QtQuick/Controls.2"); const QStringList importPaths = QQmlEngine().importPathList(); - - QStringList paths; for (const QString &importPath : importPaths) { QDir dir(importPath); if (dir.cd(targetPath)) paths += dir.absolutePath(); } + return paths; } -- cgit v1.2.3