This needs to be done in a class which derives QTextEdit or QPlainTextEdit. Do this each time the cursor moves:
format.
setBackground(QColor(0xc0,0xff,0xc0,0x80
));
selection.
format.
setProperty(QTextFormat::FullWidthSelection,
true);
selection.format = format;
selection.cursor = textCursor();
selection.cursor.clearSelection();
QList<QTextEdit::ExtraSelection> selections;
selections.append( selection );
setExtraSelections(selections);
QTextCharFormat format;
format.setBackground(QColor(0xc0,0xff,0xc0,0x80));
QTextEdit::ExtraSelection selection;
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.format = format;
selection.cursor = textCursor();
selection.cursor.clearSelection();
QList<QTextEdit::ExtraSelection> selections;
selections.append( selection );
setExtraSelections(selections);
To copy to clipboard, switch view to plain text mode
The trick is QTextEdit::setExtraSelections() . Download the code of QtCreator for some more hidden gems.
Bookmarks