tags:

views:

108

answers:

2

Hi I am using QWebView from PyQT4. I'd like to

  1. highlight terms of a webpage.
  2. do a keyboard navigation inside a webpage (for example Ctrl-N move to next link)

is it possible?

+1  A: 
  1. 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;-).

  2. 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...?

Alex Martelli
+1  A: 

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.

systempuntoout
have you tried that?
pierocampanelli
@pierocampanelli it's trivial to test
systempuntoout