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: 自定义输入框

 

相关文章:

  • 2022-12-23
  • 2021-08-10
  • 2021-12-31
  • 2021-06-04
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-07-07
  • 2021-06-24
  • 2021-07-04
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案