self.width = 24
self.height = 42
self.edit.resize(self.width, self.height)
self.document = self.edit.document()
self.document.contentsChanged.connect(self.textAreaChanged)
self.edit.setLineWrapMode(QTextEdit.NoWrap)
def textAreaChanged(self):
self.document.adjustSize()
newWidth = self.document.size().width() + 10
newHeight = self.document.size().height() + 20
if newWidth != self.edit.width():
self.edit.setFixedWidth(newWidth)
if newHeight != self.edit.height():
self.edit.setFixedHeight(newHeight)