Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Correct InputMethod for QtQuick.VirtualKeyboard / qtvirtualkeyboard

Correct InputMethod for QtQuick.VirtualKeyboard / qtvirtualkeyboard

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtvirtualkeyboavirtualkeyboardinputmethodinputcontextinputengine
1 Posts 1 Posters 731 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Predot
    wrote on 9 Jan 2022, 22:39 last edited by Predot 1 Oct 2022, 10:57
    #1

    Hello, I want to use the QtQuick.VirtualKeyboard. When I use it in the following way, I can use all features of the virtual keyboard:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.VirtualKeyboard 2.15
    
    Window {
        id: window
        width: 640
        height: 480
        visible: true
    
        TextEdit {
            id: textEdit
            height: 30
            anchors.fill: parent
        }
    
        InputPanel {
            id: inputPanel
            z: 99
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            width: window.width
        }
    }
    
    

    But I want to write a custom input method, like described here: https://doc.qt.io/qt-6/technical-guide.html#implementing-a-custom-input-method
    I tried to implement this in the following way:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.VirtualKeyboard 2.15
    
    Window {
        id: window
        width: 640
        height: 480
        visible: true
    
        TextEdit {
            id: textEdit
            height: 30
            anchors.fill: parent
            enabled: false
        }
    
        InputPanel {
            id: inputPanel
            z: 99
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            width: window.width
        }
    
        InputMethod {
            id: customInputMethod
    
            function inputModes(locale) {
                return [InputEngine.Cyrillic, InputEngine.Latin, InputEngine.Numeric];
            }
            function selectionLists() {
                return [];
            }
    
            function setInputMode(locale, inputMode) {
                return true
            }
    
            function setTextCase(textCase) {
                return true
            }
    
            function reset() {
                // TODO: reset the input method without modifying input context
            }
    
            function update() {
                // TODO: commit current state and update the input method
            }
    
            function keyEvent(key, text, modifiers) {
                var accept = true
                textEdit.text = text
                return accept;
            }
        }
    
        Component.onCompleted: {
            InputContext.inputEngine.inputMethod = customInputMethod
        }
    }
    

    But compared with the built-in input method, the virtual keyboard has now only a subset of the features. Most important for me is, that the shift key is not working, means i can only write lower case letters. Has somebody an idea to enable the shift key?

    I guess it could be solved by setting InputContext.inputMethodHints to something unequal zero, but this property is readonly. Is there a way to manipulate this property without using a text input field (the problem is that I would have to struggle with the focus of this text input field, and I dont need a text input).

    When I debug the first code snipped I can observe that InputContext.inputEngine.inputMethod has the value PlainInputMethod, but I can not find this input method as qml type (to override the keyEvent() method for my purposes).

    1 Reply Last reply
    0

    1/1

    9 Jan 2022, 22:39

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved