[Qt-creator] Extend C++ Text highlighting in Qt Creator with a plugin

Carel Combrink carel.combrink at gmail.com
Thu Nov 22 12:08:06 CET 2012


Hi,

I am trying to investigate the possibility of extending the normal C++
Syntax highlighter of Qt Creator (2.6.0) with a plugin. For the moment I am
only interested in working with comments, but in future this might extend
beyond comments.

Is it possible to extend the syntax highlighting purely using a plugin? If
yes, how would I approach this?

I have done a bit already (testing/prototyping), but could not get a good
solution, or rather any solution. This is what I have done:
I have created my own TextEditor::SyntaxHighlighter and added it to the
QTextDocument of the current editor. But if I do this, it replaces the C++
Syntax highlighter, and that functionality is lost. I though about
extending the CppHighlighter by deriving my class from it, but the
highlighter is in the Internal namespace, so that is not possible without
editing the CppEditor plugin (for now this is not an option).

My next attempt was to use a cursor to change the format (using
QTextCursor::mergeCharFormat()) of a section of the comment without using
my SyntaxHighlighter. I did this in my slot called when the document gets
updated. But this format change causes the documentUpdated() signal to be
emitted, which causes my formatter to update the format which causes… (see
the infinite loop)

I see there is a CppHighlightingSupport class in the CppTools plugin, but I
can’t figure out what this is for, nor if it will help me with my problem.
One thing that I saw about this ‘tool’ that make me think this is not the
correct things is the fact that only one can be set on the CppModelManager.
Again I can’t extend the base one since it is also Internal. And then
again, what if someone else decides to add another plugin, that also
extends the syntax highlighting. Then depending on the one that sets the
support factory last will be the one that gets used.

I don’t know how to approach this so that I can keep the highlighting that
the CppHighlighter applies and to highlight some specific sections of
comments differently.

Any help will be appreciated.
Regards,
Carel

PS: I have also posted this on the forum here (
http://qt-project.org/forums/viewthread/22115/)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20121122/55a9d917/attachment.html>


More information about the Qt-creator mailing list