In most code editors, the text highlight does not remove the syntax colors.
For example:
- Visual Studio
- Sublime Text
I would like to simulate this function in the code editor I'm making in QT; however, the text highlight turns all of the text into a single color:
vs
Would it be possible to retain the syntax highlighting during a text highlight?
FYI: I'm using a QPlainTextEdit
and QSyntaxHighlighter
to create the editor. I've tried changing the palette of the QPlainTextEdit
, but I cannot seem to find a way to disable the HighlightedText
effect.
EDIT: Here is a simplified version of the code I'm using to add some context:
void MyHighlighter::highlightBlock(const QString& text) {
// Sets characters 0 ~ 10 to be colored rgb(100, 200, 100)
QTextCharFormat temp;
temp.setForeground(QColor(100, 200, 100));
setFormat(0, 10, temp);
}