#include #include #include class dummyHighlighter : public QSyntaxHighlighter{ public: dummyHighlighter(QTextDocument *parent): QSyntaxHighlighter(parent) { } void highlightBlock(const QString &text){ QTextCharFormat myClassFormat; myClassFormat.setFontWeight(QFont::Bold); myClassFormat.setFontCapitalization(QFont::AllUppercase); myClassFormat.setForeground(Qt::darkMagenta); QString pattern = "(input)"; QRegExp expression(pattern); int index = text.indexOf(expression); while (index >= 0) { int length = expression.matchedLength(); setFormat(index, length, myClassFormat); index = text.indexOf(expression, index + length); } } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QPlainTextEdit textEdit; dummyHighlighter highlighter(textEdit.document()); textEdit.show(); return a.exec(); }