0

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 enter image description here

Web Widget Active enter image description here

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.

aoh
  • 1,090
  • 2
  • 13
  • 25
  • The problem seems to be only visual, you tried to change the background color of the menus. In Linux this effect is not observed as the following image shows: http://imgur.com/a/S2Qiu – eyllanesc Jul 26 '17 at 00:06
  • @eyllanesc What do you mean I tried to change the background color of the menus? I'm developing in Windows FYI, I will update the question to reflect that. – aoh Jul 26 '17 at 00:14
  • Also, the problem for me isn't only visual. If I were to click in the text box that says "First name", nothing would happen. I need to click below it (where it should be if the menu bar was there) for anything to happen. – aoh Jul 26 '17 at 00:20
  • You're right, I also do not notice that the scrollbars are shown, is that the whole image or has it cropped? – eyllanesc Jul 26 '17 at 00:23
  • That is the whole image. The scrollbars aren't necessary for facebook's landing page. If you load "https://en.wikipedia.org/wiki/Sierra_Nevada_(U.S.)" you will see scrollbars – aoh Jul 26 '17 at 00:26
  • I think that depends on the screen, try changing the contents of the add_web_widet method to the following: `def add_web_widet(self): self.widget = QWidget(self) self.widget.setLayout(QVBoxLayout()) self.web_widget = WebPage(self) self.widget.layout().addWidget(self.web_widget) self.setCentralWidget(self.widget)` – eyllanesc Jul 26 '17 at 00:28
  • I tried that, doesn't work unfortunately. – aoh Jul 26 '17 at 00:34
  • I think it's a bug, you should report it to pyqt5 – eyllanesc Jul 26 '17 at 00:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150126/discussion-between-aoh-and-eyllanesc). – aoh Jul 26 '17 at 00:36
  • Were you able to resolve this issue? – Michael Nov 27 '17 at 20:07
  • @Michael if you see my answer below the issue is not a PyQt problem and rather seems to be caused by Intel Driver. I was able to resolve the problem on my computer by rolling back the driver version. – aoh Nov 28 '17 at 20:44
  • Oh. Okay. I solved it by adding an import for opengl. – Michael Nov 29 '17 at 12:44

1 Answers1

2

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.

enter image description here

aoh
  • 1,090
  • 2
  • 13
  • 25