QWebView:是否可以突出显示术语并进行键盘导航?(QWebView: is it possible to highlight terms and do keyboard navigation?)

编程入门 行业动态 更新时间:2024-10-19 22:31:06
QWebView:是否可以突出显示术语并进行键盘导航?(QWebView: is it possible to highlight terms and do keyboard navigation?)

我正在使用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...?

更多推荐

本文发布于:2023-07-04 17:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:术语   键盘   QWebView   highlight   navigation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!