Hi,
I want to code a search, like the text search in FireFox.
And I've got a problem with highlighting the text. I know that the background color can be changed with QTextCharFormat::setBackground(QBrush) - but how can I do that with a part of the document and not with the whole?
My Idea was like
format.
setBackground(QBrush(Qt
::green));
cursor.setCharFormat(format);
QTextCursor cursor = this->textCursor();
cursor.movePosition(QTextCursor::StartOfLine);
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
QTextCharFormat format = cursor.charFormat();
format.setBackground(QBrush(Qt::green));
cursor.setCharFormat(format);
To copy to clipboard, switch view to plain text mode
But nothing happens. When putting the format into the QTextEdit, the whole document has the background color green.
The next problem should be, finding the Textposition in the document. But first this one ...
EDIT: I forgot to call QTextEdit::setTextCursor ... After calling this, the document is completly green in the background ...
Bookmarks