c++qtcolorsqtextedit

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


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.


Solution

  • Use text formated as HTML, for example:

    textEdit->setHtml(text);
    

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