Using multiple QSyntaxHighlighter in one QPlainTextEdit

I wrote two syntaxes: one for CSS and one for HTML. They work well.

But I want to put CSS code in the HTML code (inside the <style> tag), so I want to be able to use multiple QSyntaxHighlighter in one QPlainTextEdit.

Is there a way to do what I want? I cannot create two QSyntaxHighlighter objects in the same QPlainTextEdit, because only the second object will be used.

Thanks.

+4
source share
1 answer

You will need to independently switch between different selection modes, within the same luminance syntax.

I would start with your HTML shortcut, as it should be able to tell when you are in the <style> . Use setCurrentBlockState to mark this block as CSS and delegate it to CSS rendering.

The basic idea is illustrated in the QSyntaxHighlighter docs (switching between comment / code modes) and an example.

+1
source

All Articles