如果我有一個開放的QWebView,我喜歡它的默認上下文菜單,並在「在新窗口中打開」作爲鏈接選項。但是,當用戶請求在新窗口中打開鏈接時,我似乎無法找到採取措施。覆蓋QWebPage.createWindow方法似乎不起作用,因爲當用戶選擇在新窗口中打開鏈接時,不會調用該方法。Qt/PyQt:我如何處理QWebView/QWebPage的「在新窗口中打開」操作?
有什麼建議嗎?我正在使用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的不被調用。
謝謝,X.Jacobs。有關如何確定用戶右鍵單擊的URL /鏈接的任何建議? – 2013-02-15 19:05:25