Qml TextField数字键盘

Gui*_*pas 5 keyboard textfield qml ios

我正在尝试使用TextField仅接收中的数字的QML。我正在使用该inputMethodHints属性使设备键盘仅显示数字。它在Android上运行良好,但是当我在iOS上运行时,它会显示完整的键盘,包括数字,字符和联想词。

代码如下:

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
}
Run Code Online (Sandbox Code Playgroud)

我尝试了其他选项来喜欢inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveTextinputMethodHints: Qt.ImhNoPredictiveText但这些选项在iOS中均不起作用。

Gui*_*pas 6

我解决了删除验证器的问题,但是我不知道为什么没有验证器也能工作。

代码如下:

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
}
Run Code Online (Sandbox Code Playgroud)