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
The ONLY thing that worked for me was html.
Code snippet follows.
QString line = "contains some text from somewhere ..."
:
:
QTextCursor cursor = ui->messages->textCursor();
QString alertHtml = "";
QString notifyHtml = "";
QString infoHtml = "";
QString endHtml = "
";
switch(level)
{
case msg_alert: line = alertHtml % line; break;
case msg_notify: line = notifyHtml % line; break;
case msg_info: line = infoHtml % line; break;
default: line = infoHtml % line; break;
}
line = line % endHtml;
ui->messages->insertHtml(line);
cursor.movePosition(QTextCursor::End);
ui->messages->setTextCursor(cursor);