Hello.
I encountered the same problem, found a solution.
It's all about "qrc:/qt/qml". The search for the path "QtQuick/VirtualKeyboard/Styles" starts from there.
Accordingly, if you created a resource file not in the root of the application, then you need to add the prefix "/qt/qml/" in the resource file to the directory to your keyboard style.
Final structure (using my example):
[image: 809f17e6-f89f-4c0f-b67c-92eaddae5718.png]
Main.cpp:
int main(int argc, char *argv[])
{
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
qputenv("QT_VIRTUALKEYBOARD_STYLE", QByteArray("MXTS")); //Just style name, but before create QML engine!
J
QApplication app(argc, argv);
ModelStorage* model = ModelStorage::instance();
QQmlApplicationEngine engine;
qDebug() << engine.importPathList(); // for exmaple: QList("C:/git/Torque_sub/TorqueSub/build/Desktop_Qt_6_8_2_MSVC2022_64bit-Debug", "qrc:/qt-project.org/imports", !!!!!"qrc:/qt/qml"!!!!!, "C:/Qt/6.8.2/msvc2022_64/qml")
Style.qml:
......
keyboardBackground: Rectangle {
color: "red"
}
......
Results:
[image: f1467529-5950-4066-a296-51f9fe57c507.png]
Ref. from src virtual keyboard qt git src:
QString stylePath(const QString &name) const
{
if (name.isEmpty())
return QString();
QStringList stylePathList;
stylePathList << QLatin1String("qrc:/qt-project.org/imports/QtQuick/VirtualKeyboard/Styles/Builtin/"); //###### default styles
const QStringList importPathList = qmlImportPathList(); //###### get import paths lists
// Add QML import path (Note: the QML base dir is usually the last entry in the list)
for (int i = importPathList.size() - 1; i >= 0; --i) {
const QString stylesPath = importPathList.at(i)
+ QLatin1String("/QtQuick/VirtualKeyboard/Styles/"); //###### added, so path must: qrc:/qt/qml/QtQuick/VirtualKeyboard/Styles
stylePathList += stylesPath;
}
// Path for backwards compatibility
stylePathList << QLatin1String("qrc:/QtQuick/VirtualKeyboard/content/styles/");
for (const QString &stylePath : std::as_const(stylePathList)) {
QString filePath = buildStyleFilePath(stylePath, name);
bool pathExist = false;
pathExist = QFileInfo::exists(filePath);
if (pathExist)
return buildStylePath(stylePath, name);
}
return QString();
}
Hopefully this will save someone an hour.