PLineEdit.py 779 B

123456789101112131415161718192021222324252627
  1. from PySide6.QtWidgets import QLineEdit
  2. from PySide6.QtGui import QRegularExpressionValidator
  3. from datetime import datetime
  4. class PLineEdit(QLineEdit):
  5. def __init__(self, parent=None):
  6. super(PLineEdit, self).__init__(parent)
  7. self.setValidator(QRegularExpressionValidator(
  8. r"\d{14}", self
  9. ))
  10. self.setReadOnly(True)
  11. self.__create_id()
  12. self.selectionChanged.connect(lambda: self.setSelection(0, 0))
  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) -> None:
  18. self.__create_id()
  19. def get_value(self) -> None:
  20. return int(self.text())