You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, November 29th 2011, 4:08pm

Find & Replace option similar to QtCreator IDe

Hi,

I am implementing find & replace option for my text editor application. I want the find & replace behavior similar to the find & replace option implemented in QtCreator IDE latest one.

I am able to find word and replace word but how to set some background color to the found word or replaced word.

I tried this.

void MainWindow:: replaceText( )
{
if(textEdit->find(findLineEdit->text(), QTextDocument::FindCaseSensitively))
{
textEdit->insertPlainText(replaceLineEdit->text());
textEdit->moveCursor(QTextCursor::StartOfWord);
QTextCursor c = textEdit->textCursor();
c.select(QTextCursor::WordUnderCursor);

QTextCharFormat format = c.charFormat();
format.setBackground(Qt::green); // this will set the background of word to green
c.setCharFormat(format);

}
}

I tried this to set some background color in order to highlight the replaced word. But after textEdit gains back focus the highlighted part should come to normal and that is not happening.. I need to restore the normal background and I tried clearBackground() and it dint work for me..

Plz help me with ur ideas.

Thanks,
Haney.