Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineView content is not updated when it is displayed inside another widget
Forum Updated to NodeBB v4.3 + New Features

QWebEngineView content is not updated when it is displayed inside another widget

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 2 Posters 755 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • nekooeeN Offline
    nekooeeN Offline
    nekooee
    wrote on last edited by nekooee
    #1

    I used pyside2 and made a widget, inside which I added QWebEngineView. I wanted to call this widget wherever I wanted and pass the URL to it. When QWebEngineView is in an independent window or QStackedWidget, everything is fine. Still, when it is loaded in another widget, there is a problem, for example, when I type something, it shows the changes after I resize the window. It also has the same problem with scrolling and everything, and it doesn't show the changes until I resize the window.
    I even used QDockWidget, it works fine when there is a popup, but as soon as I drag it to the window behind it and it sticks, the same problem occurs again.

    this is my code:

    from PySide2.QtCore import Qt, QUrl
    from PySide2.QtGui import QDesktopServices
    from PySide2.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsProxyWidget, QSizePolicy, QGraphicsOpacityEffect
    from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings, QWebEnginePage
    
    
    class CustomWebEnginePage(QWebEnginePage):
        external_windows = []
    
        def acceptNavigationRequest(self, url, _type, isMainFrame):
            if _type == QWebEnginePage.NavigationTypeLinkClicked:
                QDesktopServices.openUrl(url)
                return False
            return super().acceptNavigationRequest(url, _type, isMainFrame)
    
    
    class WebViewWidget(QGraphicsView):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.scene = QGraphicsScene(self)
    
            self.setStyleSheet("*{border: 0px;background:#44475a;}")
            self.webview = QWebEngineView()
            self.webview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
            self.webview.setPage(CustomWebEnginePage(self))
            self.webview.parent()
            self.webview.loadFinished.connect(self.on_load_finished)
    
            self.opacity_effect = QGraphicsOpacityEffect()
            self.webview.setGraphicsEffect(self.opacity_effect)
            self.opacity_effect.setOpacity(0.0)
    
            self.webview.settings().setAttribute(QWebEngineSettings.ShowScrollBars, False)
    
            self.proxy = QGraphicsProxyWidget()
            self.proxy.setWidget(self.webview)
    
            self.scene.addItem(self.proxy)
            self.setScene(self.scene)
    
            self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    
            self.webview.setContextMenuPolicy(Qt.NoContextMenu)
    
        def set_url(self, url):
            self.webview.setUrl(QUrl(url))
    
        def resizeEvent(self, event):
            self.changeSize()
    
        def on_load_finished(self, success):
            if success:
                self.verticalScrollBar().setSliderPosition(0)
                self.webview.setVisible(True)
                self.changeSize()
                self.opacity_effect.setOpacity(1.0)
    
        def changeSize(self):
            self.webview.setFixedSize(self.size())
            self.showMaximized()
    

    I should also mention that I used the following template in my code, which may interfere with QWebEnginePage:

    https://github.com/Wanderson-Magalhaes/Simple_PySide_Base

    JonBJ 1 Reply Last reply
    0
    • nekooeeN nekooee

      I used pyside2 and made a widget, inside which I added QWebEngineView. I wanted to call this widget wherever I wanted and pass the URL to it. When QWebEngineView is in an independent window or QStackedWidget, everything is fine. Still, when it is loaded in another widget, there is a problem, for example, when I type something, it shows the changes after I resize the window. It also has the same problem with scrolling and everything, and it doesn't show the changes until I resize the window.
      I even used QDockWidget, it works fine when there is a popup, but as soon as I drag it to the window behind it and it sticks, the same problem occurs again.

      this is my code:

      from PySide2.QtCore import Qt, QUrl
      from PySide2.QtGui import QDesktopServices
      from PySide2.QtWidgets import QGraphicsView, QGraphicsScene, QGraphicsProxyWidget, QSizePolicy, QGraphicsOpacityEffect
      from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings, QWebEnginePage
      
      
      class CustomWebEnginePage(QWebEnginePage):
          external_windows = []
      
          def acceptNavigationRequest(self, url, _type, isMainFrame):
              if _type == QWebEnginePage.NavigationTypeLinkClicked:
                  QDesktopServices.openUrl(url)
                  return False
              return super().acceptNavigationRequest(url, _type, isMainFrame)
      
      
      class WebViewWidget(QGraphicsView):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.scene = QGraphicsScene(self)
      
              self.setStyleSheet("*{border: 0px;background:#44475a;}")
              self.webview = QWebEngineView()
              self.webview.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
              self.webview.setPage(CustomWebEnginePage(self))
              self.webview.parent()
              self.webview.loadFinished.connect(self.on_load_finished)
      
              self.opacity_effect = QGraphicsOpacityEffect()
              self.webview.setGraphicsEffect(self.opacity_effect)
              self.opacity_effect.setOpacity(0.0)
      
              self.webview.settings().setAttribute(QWebEngineSettings.ShowScrollBars, False)
      
              self.proxy = QGraphicsProxyWidget()
              self.proxy.setWidget(self.webview)
      
              self.scene.addItem(self.proxy)
              self.setScene(self.scene)
      
              self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
              self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
      
              self.webview.setContextMenuPolicy(Qt.NoContextMenu)
      
          def set_url(self, url):
              self.webview.setUrl(QUrl(url))
      
          def resizeEvent(self, event):
              self.changeSize()
      
          def on_load_finished(self, success):
              if success:
                  self.verticalScrollBar().setSliderPosition(0)
                  self.webview.setVisible(True)
                  self.changeSize()
                  self.opacity_effect.setOpacity(1.0)
      
          def changeSize(self):
              self.webview.setFixedSize(self.size())
              self.showMaximized()
      

      I should also mention that I used the following template in my code, which may interfere with QWebEnginePage:

      https://github.com/Wanderson-Magalhaes/Simple_PySide_Base

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @nekooee said in QWebEngineView content is not updated when it is displayed inside another widget:

      I should also mention that I used the following template in my code, which may interfere with QWebEnginePage:

      So how does it behave when you tried it without this additional stuff?

      nekooeeN 1 Reply Last reply
      0
      • JonBJ JonB

        @nekooee said in QWebEngineView content is not updated when it is displayed inside another widget:

        I should also mention that I used the following template in my code, which may interfere with QWebEnginePage:

        So how does it behave when you tried it without this additional stuff?

        nekooeeN Offline
        nekooeeN Offline
        nekooee
        wrote on last edited by nekooee
        #3

        @JonB When it opens in a new window that has a title bar (not used template), there is no problem. The template that I used has removed the title bar. I think there is a problem with the code of this template, but the author of the template says that the problem is not related to his project!
        See the discussion below:
        https://github.com/Wanderson-Magalhaes/Simple_PySide_Base/issues/12

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved