PLineEdit.py 804 B

12345678910111213141516171819202122232425262728293031
  1. from PySide6.QtWidgets import QLineEdit
  2. from PySide6.QtGui import QRegularExpressionValidator
  3. from datetime import datetime
  4. from PySide6.QtCore import Slot
  5. class PLineEdit(QLineEdit):
  6. def __init__(self, parent=None):
  7. super(PLineEdit, self).__init__(parent)
  8. self.setValidator(QRegularExpressionValidator(
  9. r"\d{14}", self
  10. ))
  11. self._create_id()
  12. self.textChanged.connect(
  13. self._create_id
  14. )
  15. self.textEdited.connect(
  16. self._create_id
  17. )
  18. self.cursorPositionChanged.connect(
  19. self._create_id
  20. )
  21. def clear(self) -> None:
  22. self._create_id()
  23. def _create_id(self) -> None:
  24. self.setText(datetime.now().strftime("%Y%m%d%H%M%S"))