首页 > 其他 > 详细

qml: 自定义输入框

时间:2018-08-04 19:38:29      阅读:361      评论:0      收藏:0      [点我收藏+]
import QtQuick 2.7

Rectangle {
    width: 20;
    height:  20;
    border.width: 1;
    border.color: "#E7E7E7"
    radius:  2;
    clip:true;
    property alias initTxt: txtinput.text;
    TextInput{
        id: txtinput;
        autoScroll: true;
        anchors.fill: parent;
        leftPadding: 4;
        rightPadding:4;
        clip:true;
        verticalAlignment: Text.AlignVCenter;
        selectByMouse:true;
        onEditingFinished:{
            txtinput.visible = false;
            txtLabel.visible = true;
            txtLabel.text = txtinput.text;
        }
    }
    Text {
        id: txtLabel
        anchors.fill: parent;
        leftPadding: 2;
        rightPadding: 2;
        clip:true;
        verticalAlignment: Text.AlignVCenter;
        MouseArea{
            anchors.fill: parent;
            onClicked:{
                txtLabel.visible = false;
                txtinput.visible = true;
                txtinput.text = txtLabel.text;
            }
        }
    }
}

效果:

技术分享图片

 

qml: 自定义输入框

原文:https://www.cnblogs.com/yinwei-space/p/9419418.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!