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:
Qt Code:
  1. from PyQt5.QtCore import QUrl
  2. from PyQt5.QtGui import QDesktopServices
  3. from PyQt5.QtWidgets import QApplication
  4. from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
  5.  
  6.  
  7. class WebEnginePage(QWebEnginePage):
  8. def acceptNavigationRequest(self, url, _type, isMainFrame):
  9. if _type == QWebEnginePage.NavigationTypeLinkClicked:
  10. return True
  11. return QWebEnginePage.acceptNavigationRequest(self, url, _type, isMainFrame)
  12.  
  13. class HtmlView(QWebEngineView):
  14. def __init__(self, *args, **kwargs):
  15. QWebEngineView.__init__(self, *args, **kwargs)
  16. self.setPage(WebEnginePage(self))
  17.  
  18. if __name__ == '__main__':
  19. import sys
  20.  
  21. app = QApplication(sys.argv)
  22. w = HtmlView()
  23. w.load(QUrl("https://yahoo.com"));
  24. w.show()
  25. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode 
Thanks, Max