在 QtWebView 中捕获链接点击并在默认浏览器中打开 [英] catch link clicks in QtWebView and open in default browser
本文介绍了在 QtWebView 中捕获链接点击并在默认浏览器中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 QtWebView 中打开一个页面(如果重要的话,在 PyQt 中)并且我想在系统默认浏览器中打开所有链接.IE.单击链接不应更改 QtWebView 中的站点,但应使用默认浏览器打开它.我想让用户无法在 QtWebView 中更改站点.
I am opening a page in QtWebView (in PyQt if that matters) and I want to open all links in the system default browser. I.e. a click on a link should not change the site in the QtWebView but it should open it with the default browser. I want to make it impossible to the user to change the site in the QtWebView.
我该怎么做?
谢谢,阿尔伯特
推荐答案
做到了:
import sys, webbrowser
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("http://www.az2000.de/projects/javascript-project/"))
web.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
def linkClicked(url): webbrowser.open(str(url.toString()))
web.connect(web, SIGNAL("linkClicked (const QUrl&)"), linkClicked)
web.show()
sys.exit(app.exec_())
这篇关于在 QtWebView 中捕获链接点击并在默认浏览器中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文