Qml Textfield - numeric keypad

Asked

Viewed 97 times

1

I’m trying to use a TextField who receives only numbers QML. I’m using the property inputMethodHints to make the device display only the number pad. Works well on Android but when I run on iOS it shows the complete keyboard with digits, characters and suggested words.

Code below:

TextField {
    id: numeroTelefoneTextField

    anchors.verticalCenter: parent.verticalCenter
    anchors.right: parent.right

    width: parent.width * 0.70
    height: parent.height * 0.6

    placeholderText: qsTr("Seu número")

    font.bold: true

    validator: RegExpValidator{regExp: /\d+/}

    inputMethodHints: Qt.ImhDigitsOnly
}

I tried other options like inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText and only inputMethodHints: Qt.ImhNoPredictiveText but none of these options work on iOS.

1 answer

0


I solved the problem by removing the validators, but I don’t know why it only worked without the validators.

Code below:

TextField {
    id: numeroTelefoneTextField

    anchors.verticalCenter: parent.verticalCenter
    anchors.right: parent.right

    width: parent.width * 0.70
    height: parent.height * 0.6

    placeholderText: qsTr("Seu número")

    font.bold: true

    inputMethodHints: Qt.ImhDigitsOnly
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.