Specific code is as follows:
The class pwdLineEdit: public QLineEdit
{
Q_OBJECT
Public:
Explicit pwdLineEdit (QWidget * parent=nullptr);
~ pwdLineEdit ();
Signals:
Public slots:
};
//pwdLineEdit
PwdLineEdit: : pwdLineEdit (QWidget * parent)
: QLineEdit (parent)
{
SetStyleSheet (" QLineEdit {background: transparent; Border - image: url (:/res/PWD/lineEditBkg PNG); Border - style: solid; Color: # 003 da6; Padding - left: + 8 px; Border - color: # 232423; The font: 11 px "" SimHei" "; }
""QLineEdit: hover {border: 1 px solid # 014099; }
""QLineEdit: focus {border: 1 px solid # 014099; }
""QLineEdit: hover {border: 1 px solid # 014099; }
""QLineEdit QPushButton {width: 16 px; height: 16px; Qproperty - flat: true, Margin - right: 4 px; border: none; Border - width: 0; Border - image: url (:/res/PWD/password_hide PNG) 0 0 0 0 stretch stretch; Background: transparent; }
""QLineEdit QPushButton: : checked {border - image: url (/res/PWD/password_show. PNG) 0 0 0 0 stretch stretch; } ");
SetEchoMode (QLineEdit: : ");
QPushButton * button=new QPushButton ();
The button - & gt; SetCursor (Qt: : PointingHandCursor);
The button - & gt; SetCheckable (true);
The connect (button, & amp; QPushButton: : toggled, [this] (bool checked) {
If (checked)
{
SetEchoMode (QLineEdit: : Normal);
}
The else
{
SetEchoMode (QLineEdit: : ");
}
});
QHBoxLayout * layout=new QHBoxLayout ();
Layout - & gt; AddStretch ();
Layout - & gt; AddWidget (button);
Layout - & gt; SetContentsMargins (0, 0, 0, 0);
SetLayout (layout);
}
PwdLineEdit: : ~ pwdLineEdit ()
{
}
Specific rendering is as follows:
CodePudding user response:
Don't use border - image that follow control size, or the proportion of the size of the button fixed into the picture,CodePudding user response: