Reputation: 121
Can Someone please explain the usage of QWebEngineView and QWebEnginePage in PyQt5. I want to intercept all the requests and thereby override the acceptNavigationRequest() method belonging to the QWebEnginePage class. But I am not using any QWebEnginePage object but directly implementing the QWebEngineView.
I have an input field and i am loading URL from that field using this method.
def loadURL(self):
self.load(QUrl(self.URL))
print('Loading ', self.URL)
But the links that are followed from the loaded page are what i need to handle seperately. How do i do that.
Upvotes: 2
Views: 2324
Reputation: 3542
You'll need to create a sublcass of QWebEnginePage
reimplementing acceptNavigationRequest
:
class WebEnginePage(QWebEnginePage):
def acceptNavigationRequest(self, qUrl, requestType, isMainFrame):
# return True to allow navigation, False to block it
return True
Now in your QWebEngineView
assign your new class as page using setPage
:
class WebEngineView(QWebEngineView):
def __init__(self, parent = None):
super().__init__(parent)
self.setPage(WebEnginePage(self))
Upvotes: 0