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

QTextEdit toMarkdown() function adds arbitrary linebreaks

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.2
    • GUI: Text handling
    • None
    • All

    Description

      When a block of text is parsed using toMarkdown(), it introduces linebreaks at about every 14 words. This happens regardless of the MarkdownFeatures used, nor the widget size, the wordWrapMode or the lineWrapMode.

      Please add a parameter to disable this feature when using toMarkdown.

       

      Example;

      #!/usr/bin/python3
      from PyQt5 import QtWidgets, QtGui
      
      lorem_ipsum = """What is Lorem Ipsum?
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."""
      
      
      class TextEdit(QtWidgets.QTextEdit):
          def __init__(self, parent):
              super().__init__()
              self.parent = parent
              self.isPlain = True
              self.setPlainText(lorem_ipsum)
              self.setWordWrapMode(QtGui.QTextOption.NoWrap)  # ## Has no effect
              self.setLineWrapMode(self.NoWrap)  # ## Has no effect
      
          def toggleMarkdown(self):
              if self.isPlain:
                  text = self.toPlainText()
                  self.setHtml(text)
              else:
                  text = self.toMarkdown()  # ## This function adds arbitrary line wrap at every ~14 words
                  self.setPlainText(text)
              self.isPlain = not self.isPlain
      
      
      class Main(QtWidgets.QWidget):
          def __init__(self, parent):
              super().__init__()
              self.textEdit = TextEdit(self)
              self.toggleButton = QtWidgets.QPushButton("Toggle view mode")
              self.toggleButton.clicked.connect(self.textEdit.toggleMarkdown)
              self.layout = QtWidgets.QVBoxLayout()
              self.layout.addWidget(self.toggleButton)
              self.layout.addWidget(self.textEdit)
              self.setLayout(self.layout)
              self.resize(300, 200)
              self.show()
      
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication([])
          gui = Main(app)
          app.exec()
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              william.belanger William Belanger
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes