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

这里写图片描述
当点击请添写工具名称时,光标移动到如下:
这里写图片描述
添加文字后,请填写工具名称消失:
这里写图片描述
同时设置添加文字的上限是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;

                        }
                }
            }
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值