def _check_lineedit_state(self, *args, **kwargs):
"""
Update the background color of a QLineEdit object based on whether the
input is valid.
"""
# TODO: Implement from
# http://stackoverflow.com/questions/27159575/pyside-modifying-widget-colour-at-runtime-without-overwriting-stylesheet
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)
return None
评论列表
文章目录