PDA

View Full Version : selecting that single character..



jajdoo
27th July 2010, 21:06
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;

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::FullWidt hSelection, true);
selection.cursor.clearSelection();
extraSelections.append(selection);
}

jajdoo
27th July 2010, 22:15
this worked:

selection.cursor.movePosition(QTextCursor::NextCha racter, QTextCursor::KeepAnchor, 1);

however, weirdness occurs:
if i set a background color, all is well. if a i set a foreground color it colors the original character i set out from.. why ?