有人能解释一下PyQt5中QWebEngineView和QWebEnginePage的用法吗?我想拦截所有请求,从而覆盖属于QWebEnginePage类的acceptNavigationRequest()方法。但是我没有使用任何QWebEnginePage对象,而是直接实现QWebEngineView。
我有一个输入字段,我正在使用此方法从该字段加载URL。
def loadURL(self):
self.load(QUrl(self.URL))
print('Loading ', self.URL)但是,我需要单独处理从加载的页面跟随的链接。我该怎么做呢。
发布于 2020-04-19 01:40:07
您需要创建一个重新实现acceptNavigationRequest的QWebEnginePage子类
class WebEnginePage(QWebEnginePage):
def acceptNavigationRequest(self, qUrl, requestType, isMainFrame):
# return True to allow navigation, False to block it
return True现在,在您的QWebEngineView中,使用setPage将您的新类指定为页面
class WebEngineView(QWebEngineView):
def __init__(self, parent = None):
super().__init__(parent)
self.setPage(WebEnginePage(self))https://stackoverflow.com/questions/49222292
复制相似问题