import QtQuick 2.0
import QtQuick.Controls 2.5
Rectangle {
radius: 10
border.color: "#1B7D3D"
border.width: 1
property int fontSize: 9
property string boxText: ""
property color tipColor: "#919B94"
signal textChanged()
TextInput{
id: editBox
activeFocusOnPress: true//注意这个属性
anchors.fill: parent
anchors.leftMargin: 20
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
font.pixelSize: fontSize
//font.family: robotoRegular.name
echoMode: TextInput.Password
text: boxText
onTextChanged: {
parent.textChanged()
}
}
Text{
id: tips
anchors.fill: parent
horizontalAlignment: TextInput.AlignLeft
verticalAlignment: TextInput.AlignVCenter
font.pixelSize: fontSize
color: tipColor
text: "Password"
}
MouseArea{
anchors.fill: parent
enabled: true
onPressed: {
enabled = false
tips.visible = false
//editBox.focus = true 这里这么设置在部分情况下是没有生效的,按下面的设置方式
editBox.forceActiveFocus(Qt.MouseFocusReason)
}
}
Button{
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: 35
height:23
background: Image{
id: bgImage
source: "qrc:/viewIcon.svg"
}
onClicked: {
if(editBox.echoMode == TextInput.Password)
{
editBox.echoMode = TextInput.Normal
bgImage.source = "qrc:/viewIcon1.svg"
}
else{
editBox.echoMode = TextInput.Password
bgImage.source = "qrc:/viewIcon.svg"
}
}
}
}