def check_state(self, *args, **kwargs):
"""
Update the background color of a QLineEdit object based on whether the
input is valid.
"""
sender = self.sender()
validator = sender.validator()
state = validator.validate(sender.text(), 0)[0]
if state == QtGui.QValidator.Acceptable:
color = 'none' # normal background color
elif state == QtGui.QValidator.Intermediate:
color = '#fff79a' # yellow
else:
color = '#f6989d' # red
sender.setStyleSheet('QLineEdit { background-color: %s }' % color)
评论列表
文章目录