Sorry if this is a newbie question. I have some code for marking errors in an editor and I can't find how to clear the markings when the errors are gone. Here's the method I'm calling for rendering the errors.
void Editor::highlightErrors( Thing* t )
{
if ( !t )
return;
const std::vector<Thing::Error>& errors = t->errors();
QTextCursor tc = textCursor();
tc.select(QTextCursor::Document);
QList<QTextEdit::ExtraSelection> extraSelections;
for(int i = 0; i < errors.size(); ++i) {
const Thing::Error& error = errors[i];
QTextEdit::ExtraSelection sel;
sel.format = this->errorFormat();
sel.format.setToolTip(QString(error.error.c_str()));
sel.cursor = tc;
sel.cursor.clearSelection();
sel.cursor.setPosition(error.startPos);
sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, error.endPos - error.startPos);
sel.cursor.mergeCharFormat(sel.format);
extraSelections.append(sel);
}
setExtraSelections(extraSelections);
}
I would expect QPlainTextEdit to redraw the text without the error format, when this method is called with no errors, but it doesn't. QTextLayout::draw is properly called and the extra selections are cleared as well but the text is still being drawn with the error format.
Thanks for the help.