Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[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:
PS: parcer of this forum ate all tags...
goetz last edited by
[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:
Now compare it with code on pastebin...
Also, in "preview" it shows only "text".
andre last edited by
You should set the style as a style sheet on the widget itself. Something like:
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.
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->append("<font color='blue'>this</font>: <p style='background-color: #765786; white-space: pre-wrap;'>test</p>");@
RazrFalcon, you need to use &lT; and &gT (use small T's) in your code to replace < and > to get that code working
@<p style='background-color: #765786; white-space: pre-wrap;'><font color='blue'>this</font>: test</p>@
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("<table></table><p style='white-space: pre-wrap; background-color: #edffff; margin-top:3px; margin-bottom:3px;'><font color='blue'>this</font>: test</p>");@