Guest User

Untitled

a guest
Mar 9th, 2021
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt5.QtCore import QUrl
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtWebEngineWidgets import *
  4.  
  5. app = QApplication([])
  6.  
  7.  
  8. class CustomPage(QWebEnginePage):
  9.     widgets = []
  10.     def acceptNavigationRequest(self, url, _type, isMainFrame):
  11.         if _type == self.NavigationTypeLinkClicked:
  12.             test = QLabel("Hello")
  13.             test.show()
  14.             self.widgets.append(test)
  15.             return False
  16.         return super().acceptNavigationRequest(url,  _type, isMainFrame)
  17.  
  18.  
  19. content = ("<a href=''>click</a>")
  20. htmlWidget = QWebEngineView()
  21. page = CustomPage(htmlWidget)
  22. htmlWidget.setPage(page)
  23. # htmlWidget.setHtml(content)
  24.  
  25. htmlWidget.load(QUrl("file:///home/kiba/projects/mvp/pyqt5/content-41.html"))
  26. htmlWidget.show()
  27.  
  28. app.exec_()
  29.  
RAW Paste Data