Searching for strings within a QTextBrowser?
-
Are there any built in functions for this? My end goal is to highlight words within the open page of a help document (which is a QTextBrowser) that the user searches for. I know about the QString find() function, but I'm wondering if there's something similar for QTextBrowser. Thanks in advance
-
QTextBrowser inherits "QTextEdit::find()":http://doc.trolltech.com/4.7/qtextedit.html#find
-
Is there a way to highlight every occurrence of the word in the text browser, or maybe a way to scroll through them?
-
Iterating through find() until it returns false will return each instance of the pattern. Then you can highlight or do whatever you need to.
-
Wouldn't it just return "true", not the word or location of the word? Is there a way I could make a note of the location in the browser when it returns true?
-
Per the docs, when it finds a match, it sets the cursor to select the location. You could make a copy of the cursor location with QTextEdit::textCursor() every time a location is found.
Disclaimer, it's been a while since I had to use any of this code, so your mileage may vary.
-
Looks good man, thank you
-
Hi,
This [http://doc.qt.nokia.com/4.7-snapshot/uitools-textfinder.html] example might help you. I was doing the same stuff sometime back. -
Hi,
also you can use regular expression method :
link: http://developer.qt.nokia.com/doc/qt-4.7/qml-regexpvalidator.htmlbq. Detailed Description
This element provides a validator, which counts as valid any string which matches a specified regular expression.