Qt笔记-qml-lineEdit

16 篇文章 1 订阅

qml 自定义 LineEdit

import QtQuick 2.0

FocusScope{
    id: wrapper

    property DoubleValidator doubleVal:
                DoubleValidator{
                       bottom: 10.00
                       top:50.01
                       decimals: 4 //保留小数点位数
                       //notation: DoubleValidator.StandardNotation
                       //notation: DoubleValidator.ScientificNotation
                   }
    property string hintStr: "hello world"

    Rectangle{
        id: rect

        width: 110
        height: 39

        //anchors.fill: parent

        border.color: "#C1C1C1"
        border.width: 1

        color: "white"

        radius: 2  //半径

        TextInput{
            id: input
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            anchors.left: parent.left;//iconArea.right
            anchors.leftMargin: 6
            anchors.right: parent.right
            anchors.rightMargin: 9
            horizontalAlignment: TextInput.AlignLeft
            verticalAlignment: TextInput.AlignVCenter
            font.pointSize: 14
            color: "#444444"
            clip: true

            //只接受5-120之内的值
            //validator: IntValidator{bottom: 5;top:120}

            //使用外面设定的值
            validator: doubleVal

            Text {
                id: placeHold
                font: input.font
                color: "#d0d0d0"
                opacity: input.length ? 0 : 1 //当默认提示使用
                Behavior on opacity{
                    NumberAnimation{ duration: 300 }
                }
                anchors.fill: parent
                verticalAlignment: TextInput.AlignVCenter
                text: hintStr //使用传进来的提示字符
            }
        }
    }
}

使用例子:
LineEdit
{
    x: 110
    hintStr: qsTr("只能输数字")

    doubleVal:
    DoubleValidator{
           bottom: 10.00
           top:50.01
           decimals: 5 //保留小数点位数
           notation: DoubleValidator.StandardNotation
           //notation: DoubleValidator.ScientificNotation
       }
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值