def adjust_size(self):
""" A way to reduce the height of the TextEdit. Could be implemented better.
Based on: https://stackoverflow.com/questions/9506586/qtextedit-resize-to-fit
"""
font = self.document().defaultFont() # or another font if you change it
fontMetrics = QtGui.QFontMetrics(font) # a QFontMetrics based on our font
textSize = fontMetrics.size(0, self._before)
# textWidth = textSize.width() + 30 # constant may need to be tweaked
textHeight = textSize.height() + 30 # constant may need to be tweaked
self.setMaximumHeight(textHeight)
# print('TextEdit Width/Height: {}/{}'.format(self.width(), self.height()))
# print('Text Width/Height: {}/{}'.format(textWidth, textHeight))
# print('DocSize:', self.document().size())
评论列表
文章目录