如果我有一个打开的 QWebView,我喜欢它的默认上下文菜单,其中“在新窗口中打开”作为链接选项。但是,当用户请求在新窗口中打开链接时,我似乎找不到采取行动的方法。覆盖 QWebPage.createWindow 方法似乎不起作用,因为当用户选择在新窗口中打开链接时,不会调用该方法。
有什么建议吗?我正在使用 PyQt。
示例代码:
class LocalWebPage(QWebPage):
def acceptNavigationRequest(self, webFrame, networkRequest, navigationType):
print '*acceptNavigationRequest**',webFrame, networkRequest, navigationType
return QWebPage.acceptNavigationRequest(self, webFrame, networkRequest, navigationType)
def createWindow(self, windowType):
print '--createWindow', windowType
return QWebPage.createWindow(self, windowType)
class Browser(Ui_MainWindow, QMainWindow):
def __init__(self, base, name):
...
self.page = LocalWebPage()
self.webViewMain = QWebView(self.centralwidget)
self.webViewMain.setPage(self.page)
...
我在那里有调试打印来验证 createWindow 没有被调用。