I create a QLineEdit in PyQt, and i want to hide or show the charactor of password, so i use the code below
Here is my login_ui py file login.py, you can use it to test my code within the py or import it from other py.
#in the init function, ck_pwd and ck_pay_pwd are QCheckBox, password and pay_password are QLineEdit
def init(self):
QtCore.
QObject.
connect(self.
login_ui.
ck_pwd, QtCore.
SIGNAL("stateChanged(int)"), lambda
: self.
show_or_hide_pass(self.
login_ui.
password)) QtCore.
QObject.
connect(self.
login_ui.
ck_pay_pwd, QtCore.
SIGNAL("stateChanged(int)"), lambda
: self.
show_or_hide_pass(self.
login_ui.
pay_password))
def show_or_hide_pass(self, password_obj):
if password_obj.
EchoMode()!=QtGui.
QLineEdit.
Normal: print 'normal'
password_obj.
setEchoMode(QtGui.
QLineEdit.
Normal) else:
print 'password'
password_obj.
setEchoMode(QtGui.
QLineEdit.
Password)
#in the init function, ck_pwd and ck_pay_pwd are QCheckBox, password and pay_password are QLineEdit
def init(self):
QtCore.QObject.connect(self.login_ui.ck_pwd, QtCore.SIGNAL("stateChanged(int)"), lambda : self.show_or_hide_pass(self.login_ui.password))
QtCore.QObject.connect(self.login_ui.ck_pay_pwd, QtCore.SIGNAL("stateChanged(int)"), lambda : self.show_or_hide_pass(self.login_ui.pay_password))
def show_or_hide_pass(self, password_obj):
if password_obj.EchoMode()!=QtGui.QLineEdit.Normal:
print 'normal'
password_obj.setEchoMode(QtGui.QLineEdit.Normal)
else:
print 'password'
password_obj.setEchoMode(QtGui.QLineEdit.Password)
To copy to clipboard, switch view to plain text mode
but in the function show_or_hide_pass, the password_obj.EchoMode() always be the 0 (value of QtGui.QLineEdit.Normal), it doesn't make any sense.
what's wrong with my code, Is there somebody can help?
Bookmarks