How do I set color of text and background of a QLabel ?
The ONLY thing that worked for me was html.
And I found it to be the far easier to do than any of the programmatic approaches.
The following code changes the text color based on a parameter passed by a caller.
enum {msg_info, msg_notify, msg_alert};
:
:
void bits::sendMessage(QString& line, int level)
{
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);
}