so i want to highlight matching parenthesis/braces.
i got a it working, but i cant seem to make it select a single character. i managed to highlight the entire line however, so I'm on the right track.
whenever textCursor position changes, i check if the character is for instance a closing brace. i use a method i wrote to find the 'twin' and add them to the extra selection.
problem is i just cant find a different way to have this work (the selection) other than 'QTextFormat::FullWidthSelection'. i want to highlight the specific character, but doing so in the highlighter would be too unnecessarily complicated..
QList<QTextEdit::ExtraSelection> extraSelections;
if( document()->characterAt(textCursor().position()-1) =='}')
{
selection.
format.
setBackground(QColor(Qt
::green));
selection.cursor = textCursor();
selection.cursor.setPosition(findTwinBehind());
selection.
format.
setProperty(QTextFormat::FullWidthSelection,
true);
selection.cursor.clearSelection();
extraSelections.append(selection);
}
QList<QTextEdit::ExtraSelection> extraSelections;
QTextEdit::ExtraSelection selection;
if( document()->characterAt(textCursor().position()-1) =='}')
{
selection.format.setBackground(QColor(Qt::green));
selection.cursor = textCursor();
selection.cursor.setPosition(findTwinBehind());
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor.clearSelection();
extraSelections.append(selection);
}
To copy to clipboard, switch view to plain text mode
Bookmarks