Implementing QWebEngineView Automatically Shifts GUI Upward

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Implementing QWebEngineView Automatically Shifts GUI Upward

Allan Horn

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.

It's interesting that this doesn't happen when on FullScreen mode. It is almost as if implementing QEngineView causes the GUI to visually display as if it is in FullScreenMode (even though the top "python3" bar remains) but practically the GUi still believes all the objects are located as if FullScreenMode was disabled. 

This appears to only be an issue in windows.

Development Environment Windows 10, pyqt5-5.9

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()  #  showFullScreen()
    sys.exit(app.exec_())  # only need one app, one running event loop



_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

Re: Implementing QWebEngineView Automatically Shifts GUI Upward

Cody Scott-2
This works for me (the web widget is not drawn on top of the menu item) on Windows 10 with Python 3.7.0 64-bit and

PyQt5==5.11.3
PyQt5-sip==4.19.13



On Thu, 27 Jul 2017 at 12:51, Allan Horn <[hidden email]> wrote:

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.

It's interesting that this doesn't happen when on FullScreen mode. It is almost as if implementing QEngineView causes the GUI to visually display as if it is in FullScreenMode (even though the top "python3" bar remains) but practically the GUi still believes all the objects are located as if FullScreenMode was disabled. 

This appears to only be an issue in windows.

Development Environment Windows 10, pyqt5-5.9

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()  #  showFullScreen()
    sys.exit(app.exec_())  # only need one app, one running event loop


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt