Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

TextField实用大全

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s):
Symbian
Article
Created: cuizhan (11 Oct 2011)
Last edited: hamishwillee (13 Jun 2012)

Contents

介绍

TextField 是Qt Quick Components 中用于输入和显示单行文本的控件,通过对其属性的设置,可以实现一些特定的功能,如对输入文本的限制,拼写检查等。下文将具体介绍一些特定功能的实现。

特定功能的具体实现

TextField实现密码输入

需要设置其echoMode属性和inputMethodHints属性,具体QML代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
placeholderText: "Password field"
echoMode: TextInput.Password
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
}

TextField实现输入字符的限制

需要设置其validator 属性,具体QML代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
placeholderText: "Value between 0 and 100 (mandatory field)"
validator: IntValidator{bottom: 0; top: 100;}
inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
}
注:输入的字符只能为0到100的整数

TextField实现拼写检查

需要设置其errorHighligh属性,具体代码如下:

TextArea
{
anchors {left: parent.left; right: parent.right;}
placeholderText: "Error highlight when more than 5 characters"
errorHighlight: text.length > 5
}

注: 当输入字符长度大于5,并且有拼写错误时,TextArea将显示红框

TextField实现输入无联想记忆

需要设置其inputMethodHints属性,具体代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhNoPredictiveText
}

TextField实现默认输入法为数字

需要设置其inputMethodHints属性,具体代码如下

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoPredictiveText
}

TextField实现默认输入法为大写字母

需要设置其inputMethodHints属性,具体代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhUppercaseOnly
}

TextField实现EMAIL输入

需要设置其inputMethodHints属性,具体代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhEmailCharactersOnly | Qt.ImhNoPredictiveText
}

TextField实现PhoneNumber输入

需要设置其inputMethodHints属性,具体代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhDialableCharactersOnly | Qt.ImhNoPredictiveText
}

TextField实现URL输入

需要设置其inputMethodHints属性,具体代码如下:

TextField
{
anchors {left: parent.left; right: parent.right;}
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhUrlCharactersOnly | Qt.ImhNoPredictiveText
}

代码下载

File:Qml meego textfield.zip

相关链接

Meego开发

This page was last modified on 13 June 2012, at 10:58.
371 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×