Thanks alot for pointing me to the solution for my problem, here is the code I use, it somewhat slow but its good enough for me.
void TextWidget::search(QString& str, bool matchCase)
{
QList<QTextEdit::ExtraSelection> extraSelections;
if(!ui->textEdit->isReadOnly())
{
while(ui->textEdit->find(str))
{
extra.format.setBackground(color);
extra.cursor = ui->textEdit->textCursor();
extraSelections.append(extra);
}
}
ui->textEdit->setExtraSelections(extraSelections);
}
void TextWidget::search(QString& str, bool matchCase)
{
QList<QTextEdit::ExtraSelection> extraSelections;
if(!ui->textEdit->isReadOnly())
{
ui->textEdit->moveCursor(QTextCursor::Start);
QColor color = QColor(Qt::gray).lighter(130);
while(ui->textEdit->find(str))
{
QTextEdit::ExtraSelection extra;
extra.format.setBackground(color);
extra.cursor = ui->textEdit->textCursor();
extraSelections.append(extra);
}
}
ui->textEdit->setExtraSelections(extraSelections);
}
To copy to clipboard, switch view to plain text mode
Bookmarks