I'm using a QTextEdit as a base for a "code editor" and for the syntax highlighting I'm using the QSyntaxHighlighter. It works fine, except for when the user selects code with the mouse/keyboard, the normal selection (Qt::HighlightedText) overrides the QSyntaxHighlighter selections causing all text to be white, or whatever color the Qt::HighlightedText is.

I have managed to solve it partly by overriding the paint event of QTextEdit and not setting the selection format's foreground, however this is useless since I'd have to paint the whole control myself (which I don't know how to do)..

Does anyone have any ideas?

Thanks a bunch.