Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qml TextField numeric keyboard

I am trying to use a TextField that receives only numbers in QML. I am using the inputMethodHints property to make the device keyboard show just numbers. It works fine in Android but when I run it in iOS it shows the full keyboard, with digits, characters and predictive 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 have tried other options to like inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText and just inputMethodHints: Qt.ImhNoPredictiveText but none of this options worked in iOS.

like image 499
GuiDupas Avatar asked Dec 17 '15 18:12

GuiDupas


2 Answers

I solved that just removing the validators, but I don't know why it worked without the validator.

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
}
like image 98
GuiDupas Avatar answered Nov 06 '22 16:11

GuiDupas


Try following:

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")

    validator: IntValidator {
        bottom: 1
        top: 100
    }

    font.bold: true

    inputMethodHints: Qt.ImhDigitsOnly
}
like image 4
Lisur Avatar answered Nov 06 '22 15:11

Lisur