I'm trying to highlight all strings find in a QPlainTextEdit widget , but find() will only return the first result. The following code isn't working out , why ?
(textview is a class derivated from QPlainTextEdit)
And please don't ask me to use QSyntaxHighlighter to set up colors , it's different.
QList<QTextEdit::ExtraSelection> extraSelections;
textview->moveCursor(QTextCursor::Start);
while ( textview->find(key) )
{
QTextEdit::ExtraSelection extra;
extra.cursor = textview->textCursor();
extraSelections.append(extra);
}
textview->setExtraSelections(extraSelections);
It's usually good to provide a little more detail about what doesn't work :)
QPlainTextEdit
?key
?find
finds when running with the text specified in the first two items above?I tried your code and it seems to find all the text instances correctly. The problem seems to be that you aren't actually setting any values for the format
member of extra
. After you set extra.cursor
, try setting extra.format.fontUnderline(true);
just to see if it is having any effect.