PLineEdit.py 723 B

12345678910111213141516171819202122232425
  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.setReadOnly(True)
  12. self.__create_id()
  13. def clear(self) -> None:
  14. self.__create_id()
  15. def __create_id(self) -> None:
  16. self.setText(datetime.now().strftime("%Y%m%d%H%M%S"))
  17. def mousePressEvent(self, event) -> None:
  18. self.__create_id()
  19. return super().mousePressEvent(event)