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. simplest way to highlight some part of text in QTextEdit
Qt 6.11 is out! See what's new in the release blog

simplest way to highlight some part of text in QTextEdit

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 3.0k 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.
  • S Offline
    S Offline
    saeid0034
    wrote on last edited by
    #1

    Hello, sorry if this question answered before (or there is some example of it)
    I want to show some text in QTextEdit and I want to highlight some word in it
    for example I have this very simple function to show text in QtextEdit

    def show_text(self, str):
        self.ui.textEdit.setText(str)
    

    For example I want when str is <nm> is 0x23 and #str is hi (its just a example and dont have any meaning) only <nm> and #str Highlight to other color
    I Know I can use QSyntaxHighlighter but sadly I cant find any good example of it

    1 Reply Last reply
    0
    • S Offline
      S Offline
      saeid0034
      wrote on last edited by
      #4

      I found a good example here (in question)

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

        Hi,

        The example from the documentation is pretty complete. Do you have more specific questions about it ?

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

        S 1 Reply Last reply
        2
        • SGaistS SGaist

          Hi,

          The example from the documentation is pretty complete. Do you have more specific questions about it ?

          S Offline
          S Offline
          saeid0034
          wrote on last edited by
          #3

          @SGaist thank you, but you dont have any example in python?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            saeid0034
            wrote on last edited by
            #4

            I found a good example here (in question)

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

              I haven't found it already translated but it's not the most complicated C++ code. The translation to Python is pretty straightforward.

              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

              • Login

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