开发者

QWebView: is it possible to highlight terms and do keyboard navigation?

开发者 https://www.devze.com 2023-01-01 08:26 出处:网络
I 开发者_StackOverflowam 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)

I 开发者_StackOverflowam 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消