class ResizingQLineEdit(QLineEdit): '''A QLineEdit whose sizeHint matches the text width''' def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.textChanged.connect(self.updateGeometry) def sizeHint(self) -> QtCore.QSize: hint = super().sizeHint() hint.setWidth(self.fontMetrics().width(self.text())) return hint