Hi I am using QWebView from PyQT4. I'd like to
- highlight terms of a webpage.
- do a keyboard navigation inside a webpage (for example Ctrl-N move to next link)
is it possible?
Hi I am using QWebView from PyQT4. I'd like to
is it possible?
not trivial, but possible. You could use the toHtml method of your QWebView
instance, parse it e.g. with BeautifulSoup (be sure to stick with 3.0.9!-), insert a <span class="myhilite">...</span>
around whatever terms you like (as well as the CSS to define exactly what visual effects class myhilite
is going to have), and put the modified HTML back with the setHtml
-- phew;-).
I guess you could, by using the appropriate functionality that QWebView
inherits from QWidget (I don't think QWebView
adds any extra relevant functionality of its own), e.g. grabKeyboard if you want to grab all keyboard events, or maybe addAction with an appropriate shortcut -- but I'm not sure exactly what you want to happen when control-N is pressed, so this one is iffier. Maybe you can clarify in terms of the many possible methods of QWebView
, QWidget
, etc...?
Have a look to Qwebview findText() method.
bool QWebView::findText ( const QString & subString,QWebPage::FindFlags options = 0 )
Finds the specified string, subString, in the page, using the given options.
If the HighlightAllOccurrences flag is passed, the function will highlight all occurrences that exist in the page. All subsequent calls will extend the highlight, rather than replace it, with occurrences of the new string.