[QScintilla] Trying to set different color for different set of keywords in QsciLexerCPP
Phil Thompson
phil at riverbankcomputing.com
Sat Nov 6 18:04:51 GMT 2010
On Sat, 6 Nov 2010 18:38:12 +0100, "Jonas O." <ezjonas at gmail.com> wrote:
> Hello, and first thanks for bringing Scintilla to Qt ! I'm quite happy
> to see all those nifty features made that much simple to implement
> (current line highlight, margin numbers, select line form left click
> in the margin, etc).
>
> However I'm having one little problem, I want to color some keyword
> sets with a different than other keyword sets.
> I created my own lexer by duplicating the QsciLexerCPP files, but I
> need some starting point to see how I can do that; the SendScintilla
> function is not very documented and does not forward to any scintilla
> doc (I also read it's useless to ask here to learn how to create a
> lexer, but I just want to color certain separately, not create my own
> language).
>
> I hope someone could help me at least a little, I guess someone have
> to know how to do it, the creator of QScintilla maybe ? The QScintilla
> lexer classes did not appear magically...
You don't need to create a new lexer - just subclass QsciLexerCPP and
reimplement the keywords() method to handle the case where the keyword set
is 2 (see QsciLexerCPP::KeywordSet2). You need to return a string for set 2
containing the keywords you want coloured differently. If some of these
appear in the default set 1 then you will also need to handle that set by
returning a string that doesn't contain those keywords.
You may also want to reimplement defaultColor(), defaultFont() etc. to
provide different defaults for the KeywordSet2 style.
Phil
More information about the QScintilla
mailing list