Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-112383

QGraphicsTextItem: Markdown formatting affects plain text display

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.0
    • GUI: Text handling
    • None
    • Windows

    Description

      1. With a QGraphicsTextItem, set markdown text with a strikethrough block at the end (~~), using QTextDocument::setMarkdown().
      2. Set the text back to plain text using QGraphicsTextItem::setPlainText().

      Result: The entirety of the plain text will be struck through. This also appears to occur with code blocks (`) at the end (i.e. all text becomes code format).

      If there is non-formatted text after the block, this bug does not seem to occur.

      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 not struck. ~~This is struck~~')
              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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            karen.tam@autodesk.com Karen Tam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: