PyQt WebEngineView 干扰 MainMenu [英] PyQt WebEngineView interferes with MainMenu

查看:37
本文介绍了PyQt WebEngineView 干扰 MainMenu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个包含 Web 浏览器的应用程序,但是当我添加 Web 浏览器时,我的菜单栏在视觉上消失了,但在功能上仍然存在.以下是两张图片,一张显示注释掉的self.centralWidget(self.web_widget)",另一张允许该行运行.如果您运行示例代码,您还会看到,虽然在视觉上整个网页看起来好像菜单栏不存在一样,但您必须单击每个条目字段和按钮下方的一点才能激活它,就像菜单栏实际上存在.

Web Widget 已注释掉

Web Widget 活动

示例代码

导入操作系统导入系统从 PyQt5.QtWidgets 导入 *从 PyQt5.QtCore 导入 *从 PyQt5.QtWebEngineWidgets 导入 *类网页(QWebEngineView):def __init__(self, parent=None):QWebEngineView.__init__(self)self.current_url = ''self.load(QUrl("https://facebook.com"))self.loadFinished.connect(self._on_load_finished)def _on_load_finished(self):打印(网址已加载")类 MainWindow(QMainWindow):def __init__(self, parent=None):# 初始化主窗口super(MainWindow, self).__init__(parent)self.create_menu()self.add_web_widet()自我展示()def create_menu(self):''' 创建主菜单 '''self.main_menu = self.menuBar()self.main_menu_actions = {}self.file_menu = self.main_menu.addMenu("示例文件菜单")self.file_menu.addAction(QAction("Testing Testing", self))def add_web_widet(self):self.web_widget = 网页(自我)self.setCentralWidget(self.web_widget)如果 __name__ == "__main__":app = QApplication(sys.argv)main_window = MainWindow()main_window.showMaximized()sys.exit(app.exec_()) # 只需要一个应用程序,一个运行的事件循环

开发环境Windows 10、PyQt5、pyqt5-5.9

编辑

问题似乎与菜单栏没有直接关系.即使删除菜单栏,问题仍然存在.也就是说,从 showMaximized() 更改为 showFullScreen() 似乎确实解决了问题.

解决方案

我不再认为这是 PyQt5 特有的问题,而是图形驱动程序的问题.具体来说,如果您查看 Atlassian 的 HipChat 应用程序,它有一个类似的问题,此处记录:

I'm trying to create an application that contains a web browser within it, but when I add the web browser my menu bar visually disappears but functionally remains in place. The following are two images, one showing the "self.centralWidget(self.web_widget)" commented out, and the other allows that line to run. If you run the example code, you will also see that while visually the entire web page appears as if the menu bar wasn't present, you have to click slightly below each entry field and button in order to activate it, behaving as if the menu bar was in fact present.

Web Widget Commented Out

Web Widget Active

Example Code

import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *

class WebPage(QWebEngineView):
    def __init__(self, parent=None):
        QWebEngineView.__init__(self)
        self.current_url = ''
        self.load(QUrl("https://facebook.com"))
        self.loadFinished.connect(self._on_load_finished)

    def _on_load_finished(self):
        print("Url Loaded")

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        # Initialize the Main Window
        super(MainWindow, self).__init__(parent)
        self.create_menu()
        self.add_web_widet()
        self.show()

    def create_menu(self):
        ''' Creates the Main Menu '''
        self.main_menu = self.menuBar()
        self.main_menu_actions = {}

        self.file_menu = self.main_menu.addMenu("Example File Menu")
        self.file_menu.addAction(QAction("Testing Testing", self))

    def add_web_widet(self):
        self.web_widget = WebPage(self)
        self.setCentralWidget(self.web_widget)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main_window = MainWindow()
    main_window.showMaximized()
    sys.exit(app.exec_())  # only need one app, one running event loop

Development Environment Windows 10, PyQt5, pyqt5-5.9

EDIT

The problem doesn't seem to be directly related to the menu bar. Even removing the menu bar the issue still occurs. That said, changing from showMaximized() to showFullScreen() does seem to solve the problem.

解决方案

I no longer believe this is an issue with PyQt5 specifically but rather a problem with the graphics driver. Specifically, if you look at Atlassian's HipChat application it has a similar problem which is documented here: https://jira.atlassian.com/browse/HCPUB-3177

Some individuals were able to solve the problem by running the application from the command prompt with the addendum "--disable-gpu" but that didn't work for my python application. On the other hand, rolling back the Intel(R) HD Graphics Driver did solve my problem. Version 21.20.16.4627 is the one that seems to be causing problems.

这篇关于PyQt WebEngineView 干扰 MainMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆