How to set Virtual Keyboard style from .qrc in QtWidgets application
-
I have tried for a couple of days to setup Virtual Keyboards in a Linux application. My application contains a .qrc file containing keyboard layout and styles. I tried following tons of forums to no avail, but I believe the closest I came is through following https://forum.qt.io/topic/93279/how-to-custom-qml-virtual-keyboard. Many of the guides and forums expect a QML application, and I have not succeeded in translating these to my problem.
My .qrc file is the following (with the default-style taken from here):
<RCC> <qresource prefix="/"> <file>virtual_keyboard/QtQuick/VirtualKeyboard/layouts/en_GB/main.qml</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/layouts/en_GB/numbers.qml</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/textmode-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/shift-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/shift-c5d6b6.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/shift-80c342.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/settings-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/selectionhandle-bottom.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/search-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/hidekeyboard-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/handwriting-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/globe-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/enter-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/check-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/images/backspace-fff.svg</file> <file>virtual_keyboard/QtQuick/VirtualKeyboard/Styles/style/style.qml</file> </qresource> </RCC>
I know I need the following lines to use my custom layout and specify my style, here just named 'style'. The custom layout is loaded properly, but the style is not:
qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", "qrc:/virtual_keyboard/QtQuick/VirtualKeyboard/layouts"); qputenv("QT_VIRTUALKEYBOARD_STYLE", "style"); QApplication a(argc, argv); ... return a.exec();
What I get from running my application in the following, which suggests that I am not importing from the right directory for whatever reason:
WARNING: Cannot find style "style" - fallback: "default"
What I've tried
As can be seen in the .qrc-file, I use the same path as they expect, e.g.
.../QtQuick/VirtualKeyboard/Styles/_MYSTYLENAME_/...
, where_MYSTYLENAME_ = style
.I tried putting
qputenv("QML_IMPORT_PATH", "qrc:/virtual_keyboard")
before the lines above to enforce using styles from the .qrc-file, with no luck.I've tried adding the following lines (below
QApplication a(argc, argv)
or else it wouldn't run):QQmlEngine qml_engine; qml_engine.addImportPath("qrc:/virtual_keyboard");
Thanks in advance for any help!
EDIT: This project is compiled using CMake.
EDIT2: I have also attempted setting
qputenv("QML2_IMPORT_PATH", "qrc:/virtual_keyboard")
before the otherqputenv(...)
s with no luck.