TextInput
说明
输入框
基本写法
TextInput{
id:intpu_Z
anchors.left: parent.left
anchors.leftMargin: 5
anchors.right: parent.right
anchors.rightMargin: 5
anchors.verticalCenter: parent.verticalCenter
color: "white"
font{
pointSize: maps_Root.fontSize
bold: true
}
clip: true
}
裁剪
防止输入的内容过长而超出设定的输入框。
clip: true
验证器
整数和非整数
有时候我只想要输入数字并且有指定的范围,可以用如下的方法进行书写。
//DoubleValidator 非整数
//RegExpValidator 正则表达式
validator: IntValidator{bottom: 1;top: 17}
输入掩码
可以限定你输入的内容及格式。并不强制输入,可以留空。
inputMask: ">AA_9_a"
字符(必须输入) | 字符(可留空) | 含义 |
---|---|---|
A | a | 只能输入A-Z,a-z |
N | n | 只能输入A-Z,a-z,0-9 |
X | x | 可以输入任意字符 |
9 | 0 | 只能输入0-9 |
D | d | 只能输入1-9 |
- | # | 只能输入加号(+),减号(-),0-9 |
H | h | 只能输入十六进制字符,A-F,a-f,0-9 |
B | b | 只能输入二进制字符,0或1 |
字符 | 含义 |
---|---|
> | 后面的字母字符自动转换为大写 |
< | 后面的字母字符自动转换为小写 |
! | 停止字母字符的大小写转换 |
[]{} | 括号中的内容会直接显示出来 |
|将该表中的特殊字符正常显示用作分隔符 |
回显方式
TextInput.Normal:直接显示文本(默认方式);
TextInput.Password:使用密码掩码字符(根据不同平台显示效果不同)来代替真实的字符;
TextInput.NoEcho:不显示输入的内容;
TextInput.PasswordEchoOnEdit:使用密码掩码字符,但在输入时显示真实字符。
比如输入的文本变成密码的方式。
echoMode: TextInput.PasswordEchoOnEdit
//onEditingFinished: {
// input.focus = false
// text2.text = text
//}
允许鼠标选择
允许鼠标双击或单击拖动来选中输入框内的文字。
selectByMouse: true
被选中的字体颜色
selectionColor: "sky blue"
选择框的颜色
selectionColor: "white"
以整段单词选择
mouseSelectionMode: TextInput.SelectWords
焦点
focus: true
按下回车触发
onAccepted: console.log("111")
Tab切换焦点
focus: true
KeyNavigation.tab: txIn_ID
上下、左右居中
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
输入长度限制
maximumLength:5//最长5个字符
设置只读
readOnly: true
光标
cursorVisible: false//显隐
cursorPosition: 200
文本大小写
font{
pointSize: 12
bold: true
capitalization: Font.MixedCase
capitalization: Font.AllUppercase //自动大写
capitalization: Font.AllLowercase //自动小写
capitalization: Font.SmallCaps //使用小大写,
capitalization: Font.Capitalize //默认第一个字母大写
}
文本对齐
horizontalAlignment: TextInput.AlignHCenter
horizontalAlignment: TextInput.AlignLeft
horizontalAlignment: TextInput.AlignRight
文本自动换行
wrapMode : TextInput.WrapAnywhere
文本宽高
contentHeight : real
contentWidth : real