Search code examples
qtkeyboardqmlyoctoqtvirtualkeyboard

QML Virtual Keyboard Add New Layout


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?


Solution

  • 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.