qml: 自定义输入框

时间:2023-03-09 09:37:01
qml: 自定义输入框
import QtQuick 2.7

Rectangle {
width:;
height:;
border.width:;
border.color: "#E7E7E7"
radius: 2;
clip:true;
property alias initTxt: txtinput.text;
TextInput{
id: txtinput;
autoScroll: true;
anchors.fill: parent;
leftPadding:;
rightPadding:;
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:;
rightPadding:;
clip:true;
verticalAlignment: Text.AlignVCenter;
MouseArea{
anchors.fill: parent;
onClicked:{
txtLabel.visible = false;
txtinput.visible = true;
txtinput.text = txtLabel.text;
}
}
}
}

效果:

qml: 自定义输入框