Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.4.0
-
None
Description
- With a QGraphicsTextItem, create multiple paragraphs separated by double spacing.
- Set text to markdown using QTextDocument::setMarkdown().
Result: All double spacing is eliminated in the markdown formatted text.
Adding more newlines between paragraphs does not alleviate the issue. All multiple spacing is reduced to single line spacing.
Example:
try: import PySide6.QtCore as QtCore import PySide6.QtWidgets as QtWidgets except ImportError: import PySide2.QtCore as QtCore import PySide2.QtWidgets as QtWidgets class MyTextItem(QtWidgets.QGraphicsTextItem): def __init__(self, text, parent=None): super(MyTextItem, self).__init__(parent) self.isPlain = True self.itemText = text self.setPlainText(text) def toggleMarkdown(self): if not self.isPlain: self.setPlainText(self.itemText) else: d = self.document() d.setMarkdown(self.itemText) self.isPlain = not self.isPlain class Main(QtWidgets.QWidget): def __init__(self, parent=None): super(Main, self).__init__() w = QtWidgets.QGraphicsView() s = QtWidgets.QGraphicsScene() myItem = MyTextItem('This is a paragraph.\n\nThis is another paragraph.') myItem.setPos(0, 30) s.addItem(myItem) w.setScene(s) self.toggleButton = QtWidgets.QPushButton("Toggle view mode") self.toggleButton.clicked.connect(myItem.toggleMarkdown) self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.toggleButton) self.layout.addWidget(w) self.setLayout(self.layout) self.resize(300, 200) if __name__ == '__main__': app = QtWidgets.QApplication() win = Main() win.show() app.exec_()
Attachments
Issue Links
- depends on
-
QTBUG-75662 handle CSS styling for markdown format in QTextDocument / QTextBrowser
- Reported