2

I am making a web browser using PyQt5. I am using the following code:

import PyQt5
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtWebKitWidgets import QWebView , QWebPage
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtNetwork import *
import sys
from optparse import OptionParser

class Browser(QWebView):
    def __init__(self):
        # QWebView
        self.view = QWebView.__init__(self)
        #self.view.setPage(MyBrowser())
        self.setWindowTitle('Loading...')
        self.titleChanged.connect(self.adjustTitle)
        #super(Browser).connect(self.ui.webView,QtCore.SIGNAL("titleChanged (const QString&)"), self.adjustTitle)

    def load(self,url):
        self.setUrl(QUrl(url))

    def adjustTitle(self):
        self.setWindowTitle(self.title())

app = QApplication(sys.argv)
view = Browser()
view.showMaximized()
view.load("https://duckduckgo.com")
app.exec_()

However, this is what I get:screenshot

Can someone please tell me where I am going wrong? Note that it is not a problem of the website. I have tried it with Wikipedia, Stack Overflow and Google. I am using PyQt5 version 5.10.1.

Sid
  • 2,174
  • 1
  • 13
  • 29

3 Answers3

3

In case you want fullscreen, you have to use:

class Browser(QWebView):
    def __init__(self):
        # QWebView
        self.view = QWebView.__init__(self)
        #self.view.setPage(MyBrowser())
        self.setWindowTitle('Loading...')
        self.titleChanged.connect(self.adjustTitle)
        self.showFullScreen()
Dmitrii Sidenko
  • 660
  • 6
  • 19
  • Thanks... it works. But it covers even the taskbar. Is there a way to avoid this? – Sid Aug 15 '19 at 09:46
  • Sorry, I have no access to qt compiler now. Try this solution(it's on C++, but python has the same fuctions) with available_geometry() https://stackoverflow.com/questions/2641193/qt-win-showmaximized-overlapping-taskbar-on-a-frameless-window The python has the same functions: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QDesktopWidget.html#PySide2.QtWidgets.PySide2.QtWidgets.QDesktopWidget.availableGeometry – Dmitrii Sidenko Aug 15 '19 at 10:15
  • showFullScreen is an independent property which is like a presenting mode so it will not show the border items. – Aras Nov 04 '22 at 14:52
0
class Browser(QWebView):
    def __init__(self):
        super().__init__()

    def load(self, url):
        self.setUrl(QUrl(url))

    def adjustTitle(self):
        self.setWindowTitle(self.title())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Browser()
    window.setWindowTitle('Loading...')
    window.titleChanged.connect(window.adjustTitle)
    window.load("https://duckduckgo.com")
    window.showMaximized()
    sys.exit(app.exec_())
Marco Rojas
  • 442
  • 8
  • 18
0

The program does not know the real sizes of your device so it creates a maximum on its assumed geometry.

You should provide the actual geometry by resize then call showMaximized. So that your geometry will be reachable by the program and a true maximized window will be displayed.

    self.resize(998, 878)
    self.showMaximized()
Aras
  • 60
  • 1
  • 9