Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LineEditStyleEventFilter(QObject):
- def __init__(self, lineEdit, defaultStyle, placeholderStyle, **kwargs):
- super().__init__(parent=lineEdit, **kwargs)
- self.defaultStyle = defaultStyle
- self.placeholderStyle = placeholderStyle
- lineEdit.setStyleSheet(placeholderStyle)
- lineEdit.installEventFilter(self)
- def eventFilter(self, obj, event):
- if isinstance(event, (QFocusEvent, QInputEvent)):
- if obj.text():
- obj.setStyleSheet(self.defaultStyle)
- else:
- obj.setStyleSheet(self.placeholderStyle)
- return super().eventFilter(obj, event)
- # ...
- # LineEditStyleEventFilter(someLineEdit, 'color: black', 'color: red')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement