PDA

View Full Version : QTextEdit with syntax highlighter



sarode
22nd October 2006, 11:32
Hello people!

I want to know how a QTextEdit is enabled with syntax highlighting. Can anyone give me the procedure to check 'C' programming syntax in texteditor. I tried with


QSyntaxHighlighter * syntaxHighlighter () const


but finding difficulty in using this option. Please post a reply.

jpn
22nd October 2006, 12:13
You need to subclass QSyntaxHighlighter and override:
QSyntaxHighlighter::highlightParagraph()
This function is called when necessary (the given paragraph has changed).

Just pass the text edit object to QSyntaxHighlighter's constructor. It will then install the syntax highlighter on the text edit.

QSyntaxHighlighter::QSyntaxHighlighter(QTextEdit* textEdit):

Constructs the QSyntaxHighlighter and installs it on textEdit.
It is the caller's responsibility to delete the QSyntaxHighlighter when it is no longer needed.

sarode
23rd October 2006, 07:20
Hello
Thank you for the reply.
I will try this at my end.