[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] move view to first occurence of searched string
From:       David Cortesi <davecortesi () gmail ! com>
Date:       2014-07-28 15:42:53
Message-ID: CALyzANu9Sq1jzMa8epTc6cXGg8fgMn8CL99Xn8jTOXfHb3BfJg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


> Message: 2
> Date: Mon, 28 Jul 2014 12:22:50 +0200
> From: Peter Irbizon <peterirbizon@gmail.com>
> To: pyqt <pyqt@riverbankcomputing.com>
> Subject: [PyQt] move view to first occurence of searched string
> Hello,
>
> I am displaying website with pyqt. Now I need to display/move to that part
> of site where custom text is present. Something like when I click on ctrl+f
> in browsers, write string to search and it moves me to first occurence of
> this string.
>
> How can I achieve this? Is there any sample code I can inspire from?
>

There does not appear to be a simple example of using QWebView in the Qt
docs.

In summary, you must subclass QWebView and

* supply a keyPressEvent() handler which detects ^f.

* 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.

* 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.

* If the findText() call fails, do something like beep to show it failed.

Good luck,
Dave Cortesi

[Attachment #5 (text/html)]

<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 &lt;<a \
                href="mailto:peterirbizon@gmail.com">peterirbizon@gmail.com</a>&gt;<br>
                
To: pyqt &lt;<a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a>&gt;<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>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic