views:

179

answers:

2

I have a QTextEdit box that displays text, and I'd like to be able to set the text color for different lines of text in the same QTextEditBox. (i.e. line 1 might be red, line 2 might be black, etc.)

Is this possible in a QTextEdit box? If not, what's the easiest way to get this behavior?

Thanks

+2  A: 

Use text formated as HTML, for example:

textEdit->setHtml(text);

where text, is a HTML formated text, contains with colored lines and etc.

mosg
+1  A: 

Just a quick addition: an alternative to generating the html yourself, if you're populating the text box programatically, is to use textEdit->setTextColor(QColor&). You can create the QColor object yourself, or use one of the predefined colours in the Qt namespace (Qt::black, Qt::red, etc). It will apply the specified colour to any text you add, until it is called again with a different one.

badgerr