有没有办法在 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 isQt.ImhNone
.
确实,查看源代码,这些提示调用 native 键盘(请参阅底部的代码 here - Textinput
由 TextField
在内部使用)。
因此,要定义一个仅接受数字的 TextField
,您可以这样定义:
TextField {
width: 100
height: 30
inputMethodHints: Qt.ImhDigitsOnly
}
根据设备(Android
或 iOS
、平板电脑或手机),您将看到突出显示的数字或仅数字键盘。
同样适用于您引用的其他提示,这些提示分别由 Qt.ImhEmailCharactersOnly
和 Qt.ImhUrlCharactersOnly
涵盖。
关于qt - 如何在QML中选择不同的键盘类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28234096/