[Python] QWebEngineView in PySide6 shows a static overlay over dynamic content

Discussão em 'Python' iniciado por Stack, Fevereiro 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am developing a PySide6 application that integrates a web view using QWebEngineView. However, I am encountering an issue where a static frame of the website of the web interface appears on top of the actual working website. Additionally, I noticed that when I press any key, the overlay frame updates to show the current state of the website at that exact moment. This issue occurs with any website, not just Google Earth.

    I developed the UI using Qt Designer, the added the QWebEngineView hardcoded. Here is a screenshot of the issue:

    Frame on top, working website under it

    [​IMG]

    Here's a code snippet of the part added to the Designer setupUi:

    self.stackedWidget.addWidget(self.widgets)
    self.new_page = QWidget()
    self.new_page.setObjectName(u"new_page")
    self.verticalLayout_20 = QVBoxLayout(self.new_page)
    self.verticalLayout_20.setObjectName(u"verticalLayout_20")
    self.GoogleEarth = QWebEngineView(self.new_page)
    self.GoogleEarth.setObjectName(u"GoogleEarth")

    self.verticalLayout_20.addWidget(self.GoogleEarth)

    self.GoogleEarth.setUrl(QUrl("https://earth.google.com/web/"))

    self.stackedWidget.addWidget(self.new_page)

    self.verticalLayout_15.addWidget(self.stackedWidget)


    Here's the main with MainWindow class:

    class MainWindow(QMainWindow):
    def __init__(self):
    QMainWindow.__init__(self)

    # SET AS GLOBAL WIDGETS
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    # self.ui.configureWebEngine(self)
    global widgets
    widgets = self.ui

    # USE CUSTOM TITLE BAR | USE AS "False" FOR MAC OR LINUX
    Settings.ENABLE_CUSTOM_TITLE_BAR = True

    # APP NAME
    title = "test"
    description = "test"
    # APPLY TEXTS
    self.setWindowTitle(title)
    widgets.titleRightInfo.setText(description)

    # TOGGLE MENU
    widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))

    # SET UI DEFINITIONS
    UIFunctions.uiDefinitions(self)

    # QTableWidget PARAMETERS
    widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

    # BUTTONS CLICK

    # LEFT MENUS
    widgets.btn_home.clicked.connect(self.buttonClick)
    widgets.btn_widgets.clicked.connect(self.buttonClick)
    widgets.btn_new.clicked.connect(self.buttonClick)
    widgets.btn_save.clicked.connect(self.buttonClick)

    # EXTRA LEFT BOX
    def openCloseLeftBox():
    UIFunctions.toggleLeftBox(self, True)
    widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
    widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)

    # EXTRA RIGHT BOX
    def openCloseRightBox():
    UIFunctions.toggleRightBox(self, True)
    widgets.settingsTopBtn.clicked.connect(openCloseRightBox)

    # SHOW APP
    self.show()

    # SET HOME PAGE AND SELECT MENU
    widgets.stackedWidget.setCurrentWidget(widgets.home)
    widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))


    # BUTTONS CLICK
    # Post here your functions for clicked buttons
    def buttonClick(self):
    # GET BUTTON CLICKED
    btn = self.sender()
    btnName = btn.objectName()

    # SHOW HOME PAGE
    if btnName == "btn_home":
    widgets.stackedWidget.setCurrentWidget(widgets.home)
    UIFunctions.resetStyle(self, btnName)
    btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

    # SHOW WIDGETS PAGE
    if btnName == "btn_widgets":
    widgets.stackedWidget.setCurrentWidget(widgets.widgets)
    UIFunctions.resetStyle(self, btnName)
    btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))

    # SHOW NEW PAGE
    if btnName == "btn_new":
    widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
    UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
    btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU

    if btnName == "btn_save":
    print("Save BTN clicked!")

    # PRINT BTN NAME
    print(f'Button "{btnName}" pressed!')


    # RESIZE EVENTS
    def resizeEvent(self, event):
    # Update Size Grips
    UIFunctions.resize_grips(self)

    # MOUSE CLICK EVENTS
    def mousePressEvent(self, event):
    # SET DRAG POS WINDOW
    self.dragPos = event.globalPos()

    # PRINT MOUSE EVENTS
    if event.buttons() == Qt.LeftButton:
    print('Mouse click: LEFT CLICK')
    if event.buttons() == Qt.RightButton:
    print('Mouse click: RIGHT CLICK')

    if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon("icon.ico"))
    window = MainWindow()
    window.show()
    sys.exit(app.exec())


    What I've Tried:

    • Forcing a repaint and update: I tried using repaint() and update() methods on the QWebEngineView after the page load finishes.
    • Setting a minimum size: I defined a minimum size for the QWebEngineView.
    • Using a timer: I used a QTimer to force an update after a short delay.

    Continue reading...

Compartilhe esta Página