Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Help with breaklines on PlainTextEdit
Forum Update on Monday, May 27th 2025

Help with breaklines on PlainTextEdit

Scheduled Pinned Locked Moved Solved Qt for Python
2 Posts 2 Posters 194 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Black CatB Offline
    Black CatB Offline
    Black Cat
    wrote on last edited by
    #1

    Why the PlainText was not accept the break line of the text file? Someone know some solution for this?

    text.txt content = hello\nworld

            with open('text.txt') as x:
                y = x.read()
            self.shell_host.insertPlainText(y)
    
            string = 'hello\nworld'
    
            self.shell_host.insertPlainText(string)
    

    Output:

    dc4eb2d1-047d-4c4c-a2ea-980a9d92f11b-image.png

    eyllanescE 1 Reply Last reply
    0
    • Black CatB Black Cat

      Why the PlainText was not accept the break line of the text file? Someone know some solution for this?

      text.txt content = hello\nworld

              with open('text.txt') as x:
                  y = x.read()
              self.shell_host.insertPlainText(y)
      
              string = 'hello\nworld'
      
              self.shell_host.insertPlainText(string)
      

      Output:

      dc4eb2d1-047d-4c4c-a2ea-980a9d92f11b-image.png

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @Black-Cat In the .txt you have 12 characters since "\n" is 2 characters but "\n" is a character (carrier return). A possible solution is to replace those 2 characters with the one you want:

      with open('text.txt') as x:
          y = x.read()
      y = y.replace("\\n", "\n")
      # or
      # y = y.replace(r"\n", "\n")
      self.shell_host.insertPlainText(y)
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved