spacepaste

  1.  
  2. class ResizingQLineEdit(QLineEdit):
  3. '''A QLineEdit whose sizeHint matches the text width'''
  4. def __init__(self, *args, **kwargs) -> None:
  5. super().__init__(*args, **kwargs)
  6. self.textChanged.connect(self.updateGeometry)
  7. def sizeHint(self) -> QtCore.QSize:
  8. hint = super().sizeHint()
  9. hint.setWidth(self.fontMetrics().width(self.text()))
  10. return hint
  11.