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. [SOLVED] textEdit widget different background color
Qt 6.11 is out! See what's new in the release blog

[SOLVED] textEdit widget different background color

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 6.2k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    in the textEdit widget, i would like to have line two a different background color than the first and third line. I would like the line two background color to start at the beginning of the line and ending at the end of the line where the right side of the textedit widget is. Can i have an example on how to do this please?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RazrFalcon
      wrote on last edited by
      #2

      You mean this:
      background-color:#FF0000
      ?

      "example":http://pastebin.com/sRqkEj0N

      PS: parcer of this forum ate all tags...

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        [quote author="RazrFalcon" date="1320404544"]
        PS: parcer of this forum ate all tags...[/quote]

        Just add your code into two @-tags, this preserves the special charactars and adds some nice formatting.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RazrFalcon
          wrote on last edited by
          #4

          Nope. I tried it already. Example:
          @<p >text</p>@

          Now compare it with code on pastebin...
          Also, in "preview" it shows only "text".

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You should set the style as a style sheet on the widget itself. Something like:
            @
            ui->myLineEdit->setStyleSheet("QLineEdit {background-color:#FF0000;}");
            @

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kalster
              wrote on last edited by
              #6

              i don't think i was too clear in my first post. I am not looking for a way to set all of the background to a different color like the setStyleSheet will do. I need a way to only color the second line of the textedit widget. I need all of the second line colored, not just the background of the text in line two as background-color:#FF0000 will do.

              Edit:
              i just about have it working with the code below, but it outputs "this" on one line and "test" on the other line. i would like to have it output "this test" on the same line.

              @textEdit[0]->append("<font color='blue'&gtthis</font&gt: <p style='background-color: #765786; white-space: pre-wrap;'&gttest</p&gt");@

              RazrFalcon, you need to use &lT; and &gT (use small T's) in your code to replace < and > to get that code working

              1 Reply Last reply
              0
              • R Offline
                R Offline
                RazrFalcon
                wrote on last edited by
                #7

                @&ltp style='background-color: #765786; white-space: pre-wrap;'><font color='blue'>this</font>: test</p>@
                !http://storage7.static.itmages.ru/i/11/1105/h_1320491865_9204145_052b0b8ec4.png(example)!

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #8

                  yes, that code should work as expected, but in practice the background code is not displaying. please verify

                  when i remove the <font> from the code, its displays the background color but not at the end of the line. it only displays it for the text and not for the second line of the widget

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kalster
                    wrote on last edited by
                    #9

                    i finally solved it. what i was looking for was a table in front of the background color code. that way the background is displayed for the full line, not just for the text. here is the code. i hope this helps someone.

                    @ textEdit->insertHtml("&lttable&gt&lt/table&gt&ltp style='white-space: pre-wrap; background-color: #edffff; margin-top:3px; margin-bottom:3px;'&gt&ltfont color='blue'&gtthis&lt/font&gt: test&lt/p&gt");@

                    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