Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Format all instances of specific words in QTextEdit PySide6
Qt 6.11 is out! See what's new in the release blog

Format all instances of specific words in QTextEdit PySide6

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 421 Views 2 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.
  • T Offline
    T Offline
    tIk90wT
    wrote on last edited by tIk90wT
    #1

    I've a bunch of words that needs to be formatted: emboldened, colored etc in a QTextEdit. How do I do it?

    I tried the something like the following and quickly realized it only formats the first instance.

                            sync = self.editor.document().find("word")
                            cf = QTextCharFormat()
                            cf.setFontWeight(QFont.Bold)
                            cf.setFontCapitalization(QFont.AllUppercase)
                            sync.setCharFormat(cf)
                            sync.clearSelection()
                            self.editor.setTextCursor(sync)
    

    Is QSyntaxHighligter the best/only option? I'm trying to avoid regex stuffs.

    Please forgive me for there is not enough details. I'm in a hurry but I could update the post later.

    Thank you.

    M 1 Reply Last reply
    0
    • T tIk90wT

      I've a bunch of words that needs to be formatted: emboldened, colored etc in a QTextEdit. How do I do it?

      I tried the something like the following and quickly realized it only formats the first instance.

                              sync = self.editor.document().find("word")
                              cf = QTextCharFormat()
                              cf.setFontWeight(QFont.Bold)
                              cf.setFontCapitalization(QFont.AllUppercase)
                              sync.setCharFormat(cf)
                              sync.clearSelection()
                              self.editor.setTextCursor(sync)
      

      Is QSyntaxHighligter the best/only option? I'm trying to avoid regex stuffs.

      Please forgive me for there is not enough details. I'm in a hurry but I could update the post later.

      Thank you.

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @tIk90wT
      Since QTextEdit::find(exp) find the next occurence of 'exp' at the current cursor position, you have to repeat the call to find() until it returns false.

      1 Reply Last reply
      2
      • T Offline
        T Offline
        tIk90wT
        wrote on last edited by tIk90wT
        #3

        I'm sorry I don't understand this at all!
        Does this mean when 'exp' is found, the cursor is stopped there, and I have to search from there through remaining text?

        JonBJ 1 Reply Last reply
        0
        • T tIk90wT

          I'm sorry I don't understand this at all!
          Does this mean when 'exp' is found, the cursor is stopped there, and I have to search from there through remaining text?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @tIk90wT said in Format all instances of specific words in QTextEdit PySide6:

          Does this mean when 'exp' is found, the cursor is stopped there, and I have to search from there through remaining text?

          Yes.

          1 Reply Last reply
          1

          • Login

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