Reputation: 702
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