V
V
Vladimir2020-02-12 12:27:45
Android
Vladimir, 2020-02-12 12:27:45

Why in TextFild(qml), if a mask is set, does the cursor not change position correctly?

In the qml TextField, if inputMask is set, the cursor (when entering text) moves one position, but it should, depending on the mask.
This problem manifests itself on android. On a desktop with a physical keyboard, the behavior is correct
5e43c75c7b104170406978.gif

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Item {
        anchors.fill: parent
        Column{
            spacing: 10

          anchors.horizontalCenter: parent.horizontalCenter
          anchors.top: parent.top
          anchors.topMargin: 20


            TextField{
                id:  text_field
               // inputMethodHints: Qt.ImhNoPredictiveText|Qt.ImhSensitiveData | Qt.ImhDigitsOnly
                inputMethodHints: Qt.ImhDigitsOnly
                inputMask: "+7(###)-###-####"
                onTextChanged: {
                    console.log("text changed")
                }

                Keys.onPressed: {
                    console.log("keys presed "+ event.key)
                    text_event.text= "keys presed "+ event.key


                }
                onFocusChanged: {
                    if(focus){
                        cursorPosition=0
                    }
                }
            }
            Text {
                text: text_field.text
            }
            Text {
                id: text_event

            }
        }
    }

}

Qt 5.14.1

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexanderIljin, 2020-04-21
@AlexanderIljin

I had a slightly different problem with inputMask.

inputMask: ">NNNNNN-NNNNNN-NNNNNN-NNNNNN-NNNNNN-NNNNNN;#"

If you set the cursor to the beginning of the line, then clicking on the virtual keyboard added characters before placeholders.
But this inputMethodHints helped me
inputMethodHints: Qt.ImhSensitiveData | Qt.ImhPreferUppercase | Qt.ImhNoPredictiveText

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question