PDA

View Full Version : Refreshing syntax highlighting



jpn
26th July 2006, 16:45
I have a QSyntaxHighlighter "installed" on a QTextEdit. The rules for the syntax highlighter can be dynamically altered by the user. Is there any more convenient way to tell QTextEdit/QTextDocument to refresh it's syntax highlighting than just deleting the old syntax highlighter and then creating a new one. I'm currently doing so and it works, but it seems a bit awkward to me...

elcuco
26th July 2006, 16:56
(not tested them much, but give them a try).



highlight->setDocument( null );
highlight->setDocument( textEditor->document );


I am missing this one as well... :(

jpn
26th July 2006, 17:15
Thanks for the idea, but I couldn't get it to react anyhow. The only way I have found is to create a new instance every time the rules change..

When you create an instance of your QSyntaxHighlighter subclass, pass it the QTextEdit or QTextDocument that you want the syntax highlighting to be applied to.
Isn't this a bit inconvenient..? :(

Edit: Seems that this functionality has been added to 4.2:


void QSyntaxHighlighter::rehighlight (http://doc.trolltech.com/4.2/qsyntaxhighlighter.html#rehighlight) () [slot]
Redoes the highlighting of the whole document.

elcuco
26th July 2006, 21:09
If you look in the announce forums, you will see my library for syntax higlights. I tried doying this, and on my implementation the application crahsed in ... I am not exactly sure...

I ended up killing the highlighter, and doing another one, as you did.