【问题标题】:Qml TextField numeric keyboardQml TextField 数字键盘
【发布时间】:2016-03-24 08:30:20
【问题描述】:

我正在尝试使用仅接收 QML 中的数字的 TextField。我正在使用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
}

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

【问题讨论】:

  • 对于(0-12)之间`验证器:IntValidator {底部:1;顶部:12} 焦点:真`

标签: ios keyboard qml textfield


【解决方案1】:

我解决了仅删除验证器的问题,但我不知道为什么没有验证器它会起作用。

代码如下:

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
}

【讨论】:

  • 对我来说,即使没有验证器,它也不起作用:在 Linux 上,它最初显示文字字符键盘,并且在文本输入中的任何按键上 - 开始显示数字。
【解决方案2】:

尝试以下操作:

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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 2019-03-08
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多