1
的變色部分這是我的代碼:的Qt:文本
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>");
}
因此,如果關鍵詞是「新」,這個詞是粉色的。問題在於,在「新」之後插入的所有內容也都是紅色的,而不是標準的黑色。 有人嗎? :)
更新:
愚蠢的我。剛添加ui->editor->setTextColor("#000000");
你應該回答你的問題並接受它。 – Anthony 2012-04-18 17:18:10