QTextEdit with different text colors (Qt / C++)

c++, colors, qt, qtextedit

Solution

Use text formated as HTML, for example:

textEdit->setHtml(text);

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

Problem

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 `QTextEdit` box. (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.

Original source