Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Help with Technical Guide/Keyboard Styles



  • I followed the directions I was successfully able to alter a default style for the keyboard (simple background color change) as shown in the tutorial. So this altered style was placed in QtQuck/VirtualKeyboard/Styles. Would it be possible for me to instead import this Styles directory directly into my Qt Project and reference it from there? That way, if I want my application to run on a different system I wouldn't have to have them create the application with an altered version of the default Qt install directory?



  • I believe this should be possible. I tried creating a "NewFolder" in my project directory. Inside that folder I created a directory tree: QtQuick/VirtualKeyboard/Styles/test as shown:

    rob@linux044:~/QtLocalProjects$ ls
    keyboardTest  something
    rob@linux044:~/QtLocalProjects$ cd keyboardTest/
    rob@linux044:~/QtLocalProjects/keyboardTest$ ls
    keyboardTest.pro  keyboardTest.pro.user  main.cpp  main.qml  NewFolder  qml.qrc
    rob@linux044:~/QtLocalProjects/keyboardTest$ cd NewFolder/
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder$ ls
    QtQuick
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder$ cd QtQuick/
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick$ ls
    VirtualKeyboard
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick$ cd VirtualKeyboard/
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick/VirtualKeyboard$ ls
    Styles
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick/VirtualKeyboard$ cd Styles
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick/VirtualKeyboard/Styles$ ls
    test
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick/VirtualKeyboard/Styles$ cd test
    rob@linux044:~/QtLocalProjects/keyboardTest/NewFolder/QtQuick/VirtualKeyboard/Styles/test$ ls
    images  style.qml  virtualkeyboard_default_style.qrc
    

    then in main I tried setting the import path:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[])
    {
        qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
        //qputenv("QML2_IMPORT_PATH", ":/NewFolder/QtQuick/VirtualKeyboard/Styles/test");
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.addImportPath(":/NewFolder");
        qputenv("QT_VIRTUALKEYBOARD_STYLE", "test");
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    
    

    what am I doing wrong here? Perhaps I imported the existing directory incorrectly? I just right-clicked the project name and clicked import existing directory.



  • Okay I see what I did wrong @test/virtualkeyboard_default_style.qrc the qresource prefix was set too: "/QtQuick/VirtualKeyboard/content/styles/default" instead it needed to be set too: "/QtQuick/VirtualKeyboard/content/styles/test" now it is working :)


Log in to reply