Search code examples
pythonpyqtpysideqwebview

Search text and scroll down with qwebview


I'm using Qwebview with Pyside/Qt to view an HTML page on a GUI I'm working on.

I need the possibility to add a search text function, otherwise it is useless for the purpose the GUI is made.

I've searched but I didn't find anything useful for build a code that search the text and scrolls down the page as it is made in the common browsers. The only function I found is findText but it returns a boolean and I cannot see how it can be useful.

Do somebody have an hint / advice / guide or code for this request?

Thank you.


Solution

  • Okay, so it turns out that i had an example of this using a QTextBrowser, which has a lot of this built into utility functions.

    You can still do it with a QWebBrowser though.

    Bind ctrl-f to open a search panel, and then make it so that the search box sends out two signals;

    (presuming it's a QLineEdit), returnPressed, and textChanged.

    Each of them then calls findText on the QWebPage object.

    The important part is setting the correct flag in the findText call (which you'll want to set with checkboxes in your search functionality, i'd say).

    You set the flags so that HighlightAllOccurrences is not set.

    I cannot see any way to get details on a selection. Are you sure that when you do not set the HighlightAllOccurences flag it does not scroll to the next selection automatically?