[SOLVED] textEdit widget different background color



  • 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?



  • You mean this:
    background-color:#FF0000
    ?

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

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



  • [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.



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

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



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



  • 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



  • @&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)!



  • 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



  • 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");@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.