qt - 如何在QML中选择不同的键盘类型?

标签 qt qml qtquick2

有没有办法在 QML 中为文本字段选择特定的键盘类型(例如电子邮件、网址等)? (例如,对于 iOS UIKeyboardType)

最佳答案

您可以利用inputMethodHints属性(property)。直接来自文档:

Provides hints to the input method about the expected content of the text field and how it should operate. The value is a bit-wise combination of flags, or Qt.ImhNone if no hints are set. The default value is Qt.ImhNone.

确实,查看源代码,这些提示调用 native 键盘(请参阅底部的代码 here - TextinputTextField 在内部使用)。

因此,要定义一个仅接受数字的 TextField,您可以这样定义:

TextField {
    width: 100
    height: 30
    inputMethodHints: Qt.ImhDigitsOnly
}

根据设备(AndroidiOS、平板电脑或手机),您将看到突出显示的数字或仅数字键盘。

同样适用于您引用的其他提示,这些提示分别由 Qt.ImhEmailCharactersOnlyQt.ImhUrlCharactersOnly 涵盖。

关于qt - 如何在QML中选择不同的键盘类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28234096/

相关文章:

c++ - Qt 和 mkpasswd MD5 hashes 区别

qt - 在 QML 中的 Gridview 上方显示文本

c++ - 如何在Qt中获取城市和国家列表?

qt - QML TableView 从委托(delegate)访问模型属性

user-interface - 如何创建 Qt 快速测试

c++ - 只有默认参数有效

c++ - Qt3D:如何使用Qt C++在线框模式下渲染网格?

qt - 更改 QML ListView 的模型不会更改相应的委托(delegate)

qt - QML 依赖性/可重用性(静态代码)检查器

c++ - 在 Qt Symbian C++ 中删除 QPushButton 的文本