HtmlEditor should display only a line at first, with the height just enough to hold a line, not bigger, not smaller. As the user inputs more lines, the height of HtmlEditor will get bigger too. I tried to use as follows, it didn't work. I tried to replace with self.fontSize + self.contentsMargins().top() + self.contentsMargins().bottom(). But self.contentsMargins().top() and self.contentsMargins().bottom() are always zero. I don't know why. How to do the trick?
Qt Code:
  1. class HtmlEditor(QWebView):
  2. def __init__(self, fontSize):
  3. super().__init__()
  4. self.fontSize = fontSize
  7. self.setupFont()
  8. self.sizeChange()
  10. def setupFont(self):
  11. self.htmlEditorSettings = self.settings()
  12. self.htmlEditorSettings.setFontSize(QWebSettings.DefaultFontSize, self.fontSize)
  14. def sizeChange(self):
  15. docHeight =
  16. self.setFixedHeight(docHeight)
To copy to clipboard, switch view to plain text mode