Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.15.0 RC2
-
None
Description
I make a kind of GUI using QTextEdit.
I get its string information by toHtml() method and save it.
When I want to load the same string, I get it from QDataStream, readQString().
If I don't change the QTextFrameFormat of rootFrame, (in this case , Margin default, 4.0),
I can restore the same content of QTextDocument.
But, if I change it once, the toHtml() comes to return an extra QTextBlock().
Here, this is an example: I'm from python.I'm using PySide2.
# -*- coding: utf-8 -*- from PySide2 import QtCore, QtGui, QtWidgets import PySide2 import os, sys dirname = os.path.dirname(PySide2.__file__) plugin_path = os.path.join(dirname, 'plugins', 'platforms') os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path class MyEdit(QtWidgets.QTextEdit): def __init__(self, parent=None): super(MyEdit, self).__init__(parent) document = self.document() rootFrame = document.rootFrame() rootFrameFormat = rootFrame.frameFormat() rootFrameFormat.setLeftMargin(30.5) rootFrameFormat.setRightMargin(30.5) rootFrameFormat.setTopMargin(30.5) rootFrameFormat.setBottomMargin(30) rootFrame.setFrameFormat(rootFrameFormat) self.setHtml(self.toHtml())#You can see that an extra block is added when you push cursor ↓. #An extra block is added every loading (in my application), so it results in being many empty blocks at the end of QTextDocument before I know it. #For the sake of first aid, I check the blockcount before and after, if blockcount is changed, I delete the end block. def main(): app = QtWidgets.QApplication(sys.argv) if QtWidgets.QApplication.instance() is None else QtWidgets.QApplication.instance() textedit = MyEdit() textedit.show() sys.exit(app.exec_()) if __name__ == "__main__": main()
I'm very confused when I load a content of QTextEdit.
I want to change the respective margin as I like, and I want to save the html document.
But toHtml method of QTextDocument or QTextEdit returns html with an extra block added after changing the margin of frameformat of rootFrame .
Or what am I missing?