View Full Version : qtextedit searchable?

16th June 2011, 07:53
Hi All,

I was wondering if anyone could give me some pointers on how I can make a qtextedit searchable? I want the users of my program to be able to press ctrl+f, then a little window opens where they can type in a word or sentence then press enter to cycle through all the instances of the word in the qtextedit. I would also want the instances of the word to be highlighted. You know, just like in many web browsers and many other programs.

Is there a function in Qt that can do this? Or if not, does anyone have some ideas on a good way to implement this?

If there is no easy way, I am thinking I'll have to make some signals and slots, then get the text within the textedit, search that text for the word being searched, set all the instances to red, but how move the focus to each instance with ENTER pressed? Any and all random pointers would be appreciated.

Thanks for your time!

16th June 2011, 07:57
You can search through the QTextEdit's QTextDocument (QTextEdit::document()). The QTextDocument documentation shows how to search through the text.