QML Virtual Keyboard Add New Layout

可紊 提交于 2019-12-22 00:23:57

问题


I use qt qml 5.7 on Yocto project for raspberry pi. My project need virtual keyboard for Turkish language. QT Virtual Keyboard has no support Turkish language so i want to create my custom layout. I add my project example layout codes from here as name "myCustomLayout.qml".

And I run my virtual keyboard display function by following codes.

import QtQuick 2.5
import QtQuick.VirtualKeyboard 2.1
import QtQuick.Controls 2.0

InputPanel {
    id: inputPanel
    visible:  Qt.inputMethod.visible
    height:main.height/4
    y:main.height - height
    x:main.width/8
    width: main.width*6/8
    focus: true
}

When I run the virtual keyboard display function, the appearing keyboard was not my custom layout, it still regular English keyboard layout. How can add my custom keyboard layout in my app?


回答1:


If you're using a Qt version earlier than 5.9, I think that you have to patch Qt Virtual Keyboard to add your custom layout and then rebuild it. It should be enough to modify this file by adding your own entry. For example:

contains(CONFIG, lang-tr.*) {
    LAYOUT_FILES += \
        content/layouts/tr_TR/main.qml
}

If you're using Qt 5.9 or later, you can set the QT_VIRTUALKEYBOARD_LAYOUT_PATH environment variable to the path of your custom style, as mentioned here:

The virtual keyboard layouts system supports built-in layouts as well as custom layouts. The built-in layouts are embedded as Qt Resources into the plugin binary. Custom layouts are located in the file system, so that they can be installed without recompiling the virtual keyboard itself, or they can be located in a resource file.

The selection of layouts at runtime is affected by the QT_VIRTUALKEYBOARD_LAYOUT_PATH environment variable.

In case the environment variable is not set, or contains an invalid directory, the virtual keyboard falls back to the default built-in layouts.

To prevent the built-in layouts from being built into the virtual keyboard plugin when using custom layouts, add disable-layouts to the CONFIG qmake variable. For more information, see Advanced Configuration Options.

To take an example from the module's source code, this test sets it to "/data/layouts".

As another example, suppose your application has the following directory structure:

C:\dev\temp\untitled
│   main.cpp
│   main.qml
│   resources.qrc
│   untitled.pro
│
└───en_GB
        dialpad.qml
        digits.qml
        handwriting.qml
        main.qml
        numbers.qml
        symbols.qml

You would set it to C:\dev\temp\untitled. It expects to see one or more folders, each one named after the language + country code that its layout represents, as seen here.

To verify that it's working, you can copy the en_GB layout from the link above into your project and modify it (I changed the 'Q' key to a 'Z').




回答2:


I found qtvirtualkeyboard files in yocto build path in my computer (not pi).

/build/tmp/work/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/qtvirtualkeyboard/5.7.0+gitAUTOINC+626e78c966-r0/git/

I have created a new tr_TR layout files by copying en_GB file in content/layouts path. I changed my tr_TR main.qml file. I have modified virtualkeyboard.pro file like Mitch's answer by add following lines.

contains(CONFIG, lang-tr.*) {
    LAYOUT_FILES += \
        content/layouts/tr_TR/main.qml
}

Also I modified config.pri file. I changed following lines:

# Default language
!contains(CONFIG, lang-.*) {
    contains(QT_CONFIG, private_tests) { # CI or developer build, use all languages
        CONFIG += lang-all
    } else {
        CONFIG += lang-tr_TR
    }
}

# Flag for activating all languages
lang-all: CONFIG += \
#    lang-ar_AR \
#    lang-da_DK \
#    lang-de_DE \
    lang-en_GB \
#    lang-es_ES \
#    lang-fa_FA \
#    lang-fi_FI \
#    lang-fr_FR \
#    lang-hi_IN \
#    lang-it_IT \
#    lang-ja_JP \
#    lang-ko_KR \
#    lang-nb_NO \
#    lang-pl_PL \
#    lang-pt_PT \
#    lang-ru_RU \
#    lang-sv_SE \
    lang-tr_TR \
#    lang-zh_CN \
#    lang-zh_TW

I copied my changed git file to USB stick and opened my files on pi. I rebuilt qtvirtualkeyboard with:

qmake "CONFIG+=lang-all" qtvirtualkeyboard.pro
make
make install

Finally I can use my custom layout.



来源:https://stackoverflow.com/questions/45033267/qml-virtual-keyboard-add-new-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!