我正在使用PyQT4的QWebView。 我想
突出显示网页的条款。 在网页内进行键盘导航(例如Ctrl-N移动到下一个链接)可能吗?
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?
最满意答案
不是微不足道的,但可能。 您可以使用QWebView实例的toHtml方法,例如使用BeautifulSoup解析它(确保坚持使用3.0.9! - ),在任何条件下插入<span class="myhilite">...</span>喜欢(以及用于定义myhilite将要具有的视觉效果类的CSS),并将修改后的HTML放回setHtml - phew ;-)。
我想你可以使用QWebView从QWidget继承的相应功能(我不认为QWebView会添加任何额外的相关功能),例如,如果你想获取所有键盘事件,可以使用grabKeyboard ,或者使用适当的快捷方式添加 addAction - 但是当我按下control-N时,我不确定你想要发生什么,所以这个更有效。 也许你可以澄清QWebView , QWidget等许多可能的方法......?
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...?
更多推荐
发布评论