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. Exchange Colors in QTextEdit
Forum Updated to NodeBB v4.3 + New Features

Exchange Colors in QTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 815 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Hi,

    I have a QTextEdit that consists of multi colored content. The colors are defined in a settings file.

    When I change the QTextEdit's style or apply new settings it should also repaint the old contents with the new colors.

    How would I achieve that? Is there a method to repaint all text that has a certain color?
    Or what is the best way to iterate over the existing text in order to repaint it?

    thx, Megamouse

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

      Hi
      It really depends what content is and how you colored it in first place.

      if via HTML/rich text, you will have to recreate the html and change the colors
      there.
      If you use cursor to loop over text blocks and change format, you will have to do so again.

      1 Reply Last reply
      3
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        I guess I will have to use QTextCharFormat to find out what the current color is?

        mrjjM 1 Reply Last reply
        0
        • MegamouseM Megamouse

          I guess I will have to use QTextCharFormat to find out what the current color is?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Megamouse
          Well if you are not constructing rich text with color codes so you can simply recreate with ne values, yes then you must use QCursor and QTextBlockFormat/Char to alter it

          1 Reply Last reply
          3
          • MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by
            #5

            I did that and it worked without problems. thx

            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