Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1142

QWebEngineUrlRequestInterceptor is not work under QMainWindow

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 5.13.2
    • PySide
    • None
    • python3.6.6, macOS 10.15.1, win10
    • macOS, Windows

    Description

      I want to create a QWebEngineView under QMainWindow, It's work well.

      but when I create a QWebEngineUrlRequestInterceptor for the QWebEngineView which under QMainWindow is not work.

      //代码占位符
      
      from PySide2 import QtCore, QtWidgets, QtWebEngineCore, QtWebEngineWidgets
      
      
      class WebEngineUrlRequestInterceptor(
          QtWebEngineCore.QWebEngineUrlRequestInterceptor):
          def interceptRequest(self, info):
              url = info.requestUrl().toString()
              print(url)
      
      
      class WebEngineView(QtWebEngineWidgets.QWebEngineView):
          def __init__(self, parent=None):
              super().__init__(parent)
              pass
      
      
      class MainWindow(QtWidgets.QMainWindow):
          def __init__(self, parent=None):
              super().__init__(parent)
              // not work here 
              interceptor = WebEngineUrlRequestInterceptor() 
              view = WebEngineView()
              view.page().profile().defaultProfile().setUrlRequestInterceptor( interceptor)
              view.load(QtCore.QUrl("https://www.baidu.com/"))
              self.setCentralWidget(view)
      
      
      if __name__ == '__main__':
          import sys
      
          app = QtWidgets.QApplication(sys.argv)
          main_win = MainWindow()
          main_win.show()
          sys.exit(app.exec_())
      
      

      if I use the WebEngineUrlRequestInterceptor direct, It's work fine.

      //代码占位符
      from PySide2 import QtCore, QtWidgets, QtWebEngineCore, QtWebEngineWidgets
      
      
      class WebEngineUrlRequestInterceptor(
          QtWebEngineCore.QWebEngineUrlRequestInterceptor):
          def interceptRequest(self, info):
              url = info.requestUrl().toString()
              print(url)
      
      
      class WebEngineView(QtWebEngineWidgets.QWebEngineView):
          def __init__(self, parent=None):
              super().__init__(parent)
              pass
      
      
      # class MainWindow(QtWidgets.QMainWindow):
      #     def __init__(self, parent=None):
      #         super().__init__(parent)
      #         view = WebEngineView()
      #         interceptor = WebEngineUrlRequestInterceptor()
      #         view.page().profile().defaultProfile().setUrlRequestInterceptor(
      #             interceptor)
      #         view.load(QtCore.QUrl("https://www.baidu.com/"))
      #         self.setCentralWidget(view)
      
      
      if __name__ == '__main__':
          import sys
      
          app = QtWidgets.QApplication(sys.argv)
          # main_win = MainWindow()
          # main_win.show()
          main_view = WebEngineView()
          interceptor = WebEngineUrlRequestInterceptor()
          main_view.page().profile().defaultProfile().setUrlRequestInterceptor(
              interceptor)
          main_view.load(QtCore.QUrl("https://www.baidu.com/"))
          main_view.show()
          sys.exit(app.exec_())
      
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            wuyue wuyue
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes