diff options
-rw-r--r-- | src/controls/Private/qquickcontrolsettings.cpp | 38 | ||||
-rw-r--r-- | src/controls/Private/qquickcontrolsettings_p.h | 1 | ||||
-rw-r--r-- | tests/auto/customcontrolsstyle/style.qrc | 3 | ||||
-rw-r--r-- | tests/auto/customcontrolsstyle/tst_customcontrolsstyle.cpp | 1 |
4 files changed, 30 insertions, 13 deletions
diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp index dfab577e..1965738a 100644 --- a/src/controls/Private/qquickcontrolsettings.cpp +++ b/src/controls/Private/qquickcontrolsettings.cpp @@ -42,6 +42,7 @@ #include <qcoreapplication.h> #include <qdebug.h> #include <qqmlengine.h> +#include <qfileinfo.h> #include <qlibrary.h> #include <qdir.h> #include <QTouchDevice> @@ -154,16 +155,21 @@ static QString relativeStyleImportPath(QQmlEngine *engine, const QString &styleN QString path; #ifndef QT_STATIC bool found = false; - const auto importPathList = engine->importPathList(); - for (const QString &import : importPathList) { - QDir dir(import + QStringLiteral("/QtQuick/Controls/Styles")); - if (dir.exists(styleName)) { - found = true; - path = dir.absolutePath(); - break; + const auto importPathList = engine->importPathList(); // ideally we'd call QQmlImportDatabase::importPathList(Local) here, but it's not exported + for (QString import : importPathList) { + bool localPath = QFileInfo(import).isAbsolute(); + if (import.startsWith(QLatin1String("qrc:/"), Qt::CaseInsensitive)) { + import = QLatin1Char(':') + import.mid(4); + localPath = true; + } + if (localPath) { + QDir dir(import + QStringLiteral("/QtQuick/Controls/Styles")); + if (dir.exists(styleName)) { + found = true; + path = dir.absolutePath(); + break; + } } - if (found) - break; } if (!found) path = ":/QtQuick/Controls/Styles"; @@ -194,6 +200,7 @@ static QString styleImportPath(QQmlEngine *engine, const QString &styleName) } QQuickControlSettings1::QQuickControlSettings1(QQmlEngine *engine) + : m_engine(engine) { // First, register all style paths in the default style location. QDir dir; @@ -223,10 +230,14 @@ QQuickControlSettings1::QQuickControlSettings1(QQmlEngine *engine) if (m_styleMap.contains(m_name)) { m_path = m_styleMap.value(m_name).m_styleDirPath; } else { - QString unknownStyle = m_name; - m_name = defaultStyle; m_path = m_styleMap.value(defaultStyle).m_styleDirPath; - qWarning() << "WARNING: Cannot find style" << unknownStyle << "- fallback:" << styleFilePath(); + // Maybe the requested style is not next to the default style, but elsewhere in the import path + findStyle(engine, m_name); + if (!m_styleMap.contains(m_name)) { + QString unknownStyle = m_name; + m_name = defaultStyle; + qWarning() << "WARNING: Cannot find style" << unknownStyle << "- fallback:" << styleFilePath(); + } } // Can't really do anything about this failing here, so don't bother checking... @@ -278,7 +289,8 @@ void QQuickControlSettings1::findStyle(QQmlEngine *engine, const QString &styleN QDir dir; dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); dir.setPath(path); - dir.cd(styleName); + if (!dir.cd(styleName)) + return; StyleData styleData; diff --git a/src/controls/Private/qquickcontrolsettings_p.h b/src/controls/Private/qquickcontrolsettings_p.h index aa3e4b2d..bfa44f2f 100644 --- a/src/controls/Private/qquickcontrolsettings_p.h +++ b/src/controls/Private/qquickcontrolsettings_p.h @@ -106,6 +106,7 @@ private: QString m_name; QString m_path; QHash<QString, StyleData> m_styleMap; + QQmlEngine *m_engine; }; QT_END_NAMESPACE diff --git a/tests/auto/customcontrolsstyle/style.qrc b/tests/auto/customcontrolsstyle/style.qrc index 37cfbbd7..c04782ba 100644 --- a/tests/auto/customcontrolsstyle/style.qrc +++ b/tests/auto/customcontrolsstyle/style.qrc @@ -2,4 +2,7 @@ <qresource prefix="/"> <file>Style/ButtonStyle.qml</file> </qresource> + <qresource prefix="/qt-project.org/imports/QtQuick/Controls/Styles/ResourceStyle"> + <file alias="ButtonStyle.qml">Style/ButtonStyle.qml</file> + </qresource> </RCC> diff --git a/tests/auto/customcontrolsstyle/tst_customcontrolsstyle.cpp b/tests/auto/customcontrolsstyle/tst_customcontrolsstyle.cpp index ebd60d1e..99e8240e 100644 --- a/tests/auto/customcontrolsstyle/tst_customcontrolsstyle.cpp +++ b/tests/auto/customcontrolsstyle/tst_customcontrolsstyle.cpp @@ -61,6 +61,7 @@ void tst_customcontrolsstyle::style_data() QTest::newRow("NonExistentStyle") << QString::fromLatin1("NonExistentStyle") << QString::fromLatin1("Base"); QTest::newRow("CustomFileSystemStyle") << directory() + QString::fromLatin1("/Style") << QString::fromLatin1("Style"); + QTest::newRow("BuiltinQrcStyle") << QString::fromLatin1("ResourceStyle") << QString::fromLatin1("ResourceStyle"); // from :/qt-project.org/imports/QtQuick/Controls/Styles QTest::newRow("CustomQrcStyle") << QString::fromLatin1(":/Style") << QString::fromLatin1("Style"); } |