您的位置:首页 > 其它

qml中TextField实现添加文字的上限,同时添加文字时,提示文字消失。

2018-01-21 14:32 1366 查看


当点击请添写工具名称时,光标移动到如下:



添加文字后,请填写工具名称消失:



同时设置添加文字的上限是31个字符,当超过31个就不能再添加。

相关代码:

import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4

Rectangle{
id:toolsDisp;
width:250;
height:60;

//设置工具名称
function setTaskName( name ){
taskName.text = name ;
}
function getToolsName(){
return toolsName.text;
}
function setToolName(name){
toolsName.text=name;
}
Row{
spacing: 10;
anchors.top: parent.top;
anchors.topMargin: 10;

Column{
id:taskNameColumn
Text{
id:taskNameHead
text:"任务"
font.pointSize: 12
font.bold: true
}

Text{
id:taskName;
anchors.top: taskNameHead.bottom
anchors.topMargin: 5
text:"模板1"
font.pointSize: 8
color: "#313a4b"
}
}

Column{
id:toolNameColumn;
anchors.left: taskNameColumn.right
anchors.leftMargin: 100
Text{
id:toolsNameHead;
text:"工具名称"
font.pointSize: 12
font.bold: true
}

TextField{

id:toolsName;
//text: "请填写工具名称"
placeholderText: "请填写工具名称"
font.pointSize: 8
textColor:"#313a4b"
maximumLength:31
style: TextFieldStyle{
background: Rectangle{
opacity: 1;

}
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐