I've kinda hard coded this:
longestLineLength = 0
for line in text.split("\n"):
linelength = len(line)
if linelength >longestLineLength :
longestLineLength = linelength
numOfLinesInText = text.count("\n") + 2
textEdit.setFixedHeight(numOfLinesInText*15)
textEdit.setFixedWidth(longestLineLength*5.7)