def welcomeStage (self):
self.test = QtGui.QLineEdit (self)
self.test.move (50, 150)
QtCore.QObject.connect (self.test, QtCore.SIGNAL ('returnPressed()'), self.passwordStage)
def passwordStage (self):
self.email = self.test.text()
self.test.clear()
self.test.setEchoMode (QtGui.QLineEdit.Password)
QtCore.QObject.connect (self.test, QtCore.SIGNAL ('returnPressed()'), self.loginStage)
def loginStage (self):
self.pwd = self.test.text()
print self.pwd
if len (self.pwd) < 0:
welcomeStage ()
return
Simply put, I am making a login form. The user enters their email, then the text field is cleared and echo mode is set to Password mode. The text() function returns the email fine, but when I call text() after I have changed the echo mode, it returns 0. I've been pouring over the documentation lo开发者_如何学Coking for anything regarding the text() function and how it operates when Password mode is on, however I have not found anything. Does anybody know how this is done?
I can't offer a fix for using a QLineEdit
, but you can get passwords in a QInputDialog
by specifying mode in the getText()
method. Like this:
diag = QtGui.QInputDialog
s = None
while s is None:
qstring, ok = diag.getText(self, QtCore.QString(title), QtCore.QString(text), mode=QtGui.QLineEdit.Password)
s = str(qstring)
if ok is False: # user pressed Cancel
return None
if s == '': # user entered nothing
s = None
return s
精彩评论