<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Message: 2<br>
Date: Mon, 28 Jul 2014 12:22:50 +0200<br>
From: Peter Irbizon <<a href="mailto:peterirbizon@gmail.com">peterirbizon@gmail.com</a>><br>
To: pyqt <<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>><br>
Subject: [PyQt] move view to first occurence of searched string<br>
Hello,<br>
<br>
I am displaying website with pyqt. Now I need to display/move to that part<br>
of site where custom text is present. Something like when I click on ctrl+f<br>
in browsers, write string to search and it moves me to first occurence of<br>
this string.<br>
<br>
How can I achieve this? Is there any sample code I can inspire from?<br></blockquote><div><br></div><div>There does not appear to be a simple example of using QWebView in the Qt docs.<br><br></div><div>In summary, you must subclass QWebView and <br>

<br></div><div>* supply a keyPressEvent() handler which detects ^f.<br><br></div><div>* On ^f put up a modal dialog (QInputDialog) to get some text to look for. Alternatively, you could query QWebView.selectedText() to get text the user has selected already, and search for that, put up the dialog only if that is null.<br>

<br></div><div>* Pass that text to QWebView.findText() to select the next occurrence.   Pass FindWrapsAroundDocument to wrap around. Now if the user hits ^f again, the found text is selected, so this is find-again. User has to click to clear selection to start new find.<br>

<br></div><div>* If the findText() call fails, do something like beep to show it failed.<br><br></div><div>Good luck,<br></div><div>Dave Cortesi<br></div><div><br></div><div><br><br></div></div></div></div>