Reputation: 5629
I'm porting a software from PyQt4 to PyQt5.
With PyQt4, I used to use a QWebView to render html strings (so, no web browsing, just some rendering). Therefore, I could disable "browsing" with this setting:
self.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
Where self
was my QWebView.
However, I'm now forced to QtWebEngineWidgets.QWebEngineView
. It's not that bad, but I can't use the previous setting anymore.
QtWebEngineWidgets.QWebEnginePage
doesn't have the DelegateAllLinks setting.
I would like to disable all the links in the view, so the user won't be able to click one of them and mess up with my software.
Do you have any idea ?
Upvotes: 1
Views: 1057
Reputation: 120718
Firstly: are you absolutely sure you need to use a full web browser just to render some static html? The QTextBrowser class only supports a limited subset of HTML4, but if your html is simple it would be a much better choice than a super-heavyweight class like QWebEngineView
.
Anyway, if you really must use the QWebEngineView
class, the only alternative to setLinkDelegationPolicy
is to reimplement the acceptNavigationRequest method of the web-page:
class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
def acceptNavigationRequest(self, url, navtype, mainframe):
return False
Upvotes: 4