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. The font setting becomes invalid after deleting the current line of a textBrowser

The font setting becomes invalid after deleting the current line of a textBrowser

Scheduled Pinned Locked Moved Qt for Python
7 Posts 2 Posters 972 Views 1 Watching
  • 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.
  • feiyuhuahuoF Offline
    feiyuhuahuoF Offline
    feiyuhuahuo
    wrote on last edited by
    #1

    I have a button and the slot connected to it is:

        def add_a(self):
            lastLine = self.main_ui.textBrowser_3.textCursor()
            lastLine.select(QTextCursor.LineUnderCursor)
            lastLine.removeSelectedText()
    
            self.aa = str(self.aa + 'a')
            self.main_ui.textBrowser_3.append(self.aa)
    

    Every time a new line is appended to the textBrowser, the current line is deleted first. The initial self.aa is 'a'. I found the font is changed after the slot is called once.
    The first result:
    ed761bf9-f4d2-40bf-8b55-60ce5224f1c8-image.png
    Then the font looks different ever.
    8d44fbf6-4afd-4ca9-ad73-53e403153e28-image.png
    1f2443ad-dcd2-4c8c-be88-4c2ce0d4ab0a-image.png
    Seems the font setting is invalid. How to solve this? I did not change other things, just keep clicking the button.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      Do I see correctly that you empty the text edit before adding the new line ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • feiyuhuahuoF Offline
        feiyuhuahuoF Offline
        feiyuhuahuo
        wrote on last edited by
        #3

        @SGaist Yes, I empty the current line before adding the new line.

        1 Reply Last reply
        0
        • feiyuhuahuoF Offline
          feiyuhuahuoF Offline
          feiyuhuahuo
          wrote on last edited by
          #4

          @SGaist
          I did another test with the above code. If the textBrowser is empty at the begining, then the text did not move to the second line and the font changed. But if the textBrowser has some text at the begining, then the new text can move to the second line and the font is OK. Do you know why?
          ee5f8d75-5ef5-42bf-8217-e48a3ebad7bb-image.png

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            IIRC, the fact that the whole text is nuked has the side effect of also deleting the style associated with it.

            What do you get if you select the current text and overwrite it ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • feiyuhuahuoF Offline
              feiyuhuahuoF Offline
              feiyuhuahuo
              wrote on last edited by
              #6

              @feiyuhuahuo said in The font setting becomes invalid after deleting the current line of a textBrowser:

              removeSelectedText

              @SGaist
              How to overwrite the text?

                      lastLine = self.main_ui.textBrowser_3.textCursor()
                      lastLine.select(QTextCursor.LineUnderCursor)
                      self.aa += 'a'
                      lastLine.insertText(self.aa)
              

              I tried the above code, but it's useless. The font format is still not right.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                One workaround: change the selection so that it's all the letter except the first one, replace the text, delete the first char.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

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