raze
raze

Reputation: 702

Qt: change color part of text

This is my code:

QTextCursor cursor = ui->editor->textCursor(); // editor is QTextEdit
cursor.select(QTextCursor::WordUnderCursor);
QString c = cursor.selectedText();

if (c == keywords[i])
{
    cursor.removeSelectedText();
    cursor.insertHtml("<font color=\"DeepPink\">" + keywords[i] + "</font>");
}

So, if the keyword is "new", this word is colored pink. The problem is that everything that is inserted after "new" is also colored red, and not the standard black. Anybody? :)

UPDATE:

Stupid me. Just added ui->editor->setTextColor("#000000");

Upvotes: 1

Views: 1739

Answers (1)

raze
raze

Reputation: 702

ui->editor->setTextColor("#000000");

Upvotes: 1

Related Questions