Clicking any link even _blank opens in same window Qwebengine
I have this code that suppose to visit/follow any link that I click in the same Main window even if they are supposed to open in new window in Qwebengine instead of right clicking then clicking "Follow link" from context menu but for some reason it doesn't work as expected.
Here is the code:
Code:
from PyQt5.
QtCore import
QUrlfrom PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
class WebEnginePage(QWebEnginePage):
def acceptNavigationRequest(self, url, _type, isMainFrame):
if _type == QWebEnginePage.NavigationTypeLinkClicked:
return True
return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame)
class HtmlView(QWebEngineView):
def __init__(self, *args, **kwargs):
QWebEngineView.__init__(self, *args, **kwargs)
self.setPage(WebEnginePage(self))
if __name__ == '__main__':
import sys
w = HtmlView()
w.
load(QUrl("https://yahoo.com"));
w.show()
sys.exit(app.exec_())
Thanks, Max