PDA

View Full Version : what's wrong with my setEchoMode code



catchxiaoshuang
13th June 2015, 04:29
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 11205, 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)

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?

ChrisW67
13th June 2015, 06:41
Line 8, the property name is echoMode() not EchoMode().

catchxiaoshuang
13th June 2015, 10:18
oh, what a fuck!!
that is the problem.
thanks a lot

ChrisW67
13th June 2015, 21:09
Perhaps PyChecker (http://pychecker.sourceforge.net/) or Pylint (http://docs.pylint.org/intro.html) would have flagged this for you.