Qt virtual keyboard deault layout is different

118 Views Asked by At

When i run QT virtual keyboard on my device layout is this

layout on device

but on QT website default layout for keyboard is like this

qt website layout

Why it is two default are different ? and how can i have second layout instead of first ?

1

There are 1 best solutions below

2
Stephen Quan On

[EDIT/REWRITE]

There are two things I wanted to cover in this answer:

  1. Switching between British English (en_GB) and Slovenčina (sl_SL) keyboards can be done via setting VirtualKeyboardSettings.locale
  2. Changing keyboard layouts can be done by setting the QT_VIRTUALKEYBOARD_LAYOUT_PATH environment variable

The reference documentation appears to show the keyboard in British English and using the older Qt5.15.x keyboard layouts.

// main.qml
Component.onCompleted: VirtualKeyboardSettings.locale = "en_GB"
// main.cpp
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", "C:/Qt/Qt5.15.6/5.15.6/Src/qtvirtualkeyboard/src/virtualkeyboard/content/layouts");

N.B. On my computer I had both Qt6.6.1 and Qt5.15.6 installed so I did the above to my main.cpp so that I can test the keyboard switch. To do it properly, you would need to move the keyboard layouts into your application resources and update QT_VIRTALKEYBOARD_LAYOUT_PATH to match.

Here's a minimum application:

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.VirtualKeyboard
import QtQuick.VirtualKeyboard.Settings
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    ColumnLayout {
        id: columnLayout
        width: parent.width
        RowLayout {
            Button {
                text: "en_GB"
                checkable: true
                checked: VirtualKeyboardSettings.locale === "en_GB";
                onClicked: {
                    VirtualKeyboardSettings.locale = "en_GB";
                    textEdit.forceActiveFocus();
                }
            }
            Button {
                text: "sl_SL"
                checkable: true
                checked: VirtualKeyboardSettings.locale === "sl_SL";
                onClicked: {
                    VirtualKeyboardSettings.locale = "sl_SL";
                    textEdit.forceActiveFocus();
                }
            }
        }
        Frame {
            Layout.fillWidth: true
            TextEdit {
                id: textEdit
                width: parent.width
                text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                wrapMode: Text.Wrap
            }
        }
        Button {
            text: qsTr("Submit")
        }
    }
    Component.onCompleted: {
        VirtualKeyboardSettings.locale = "en_GB";
        textEdit.forceActiveFocus();
    }
    InputPanel {
        id: inputPanel
        y: active ? parent.height - height : parent.height
        width: parent.width
    }
}

Here's a screengrab using Qt6.x keyboard layouts:

KeyboardApp.gif

Here's a screengrab using Qt5.15.6 keyboard layouts:

KeyboardApp2.gif

References: