Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt5 : QWebEngineView doesn't load URL

I'm trying to make a browser, using Python 3.10.4 & PyQt5 v5.15.6, in a virtual environment (venv).

My problem is that QWebEngineView doesn't load URL, so I just have a blank window.

Here is my code:

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


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        self.browser.load(QUrl('https://www.google.com'))
        self.browser.loadFinished.connect(self.test)
        self.setCentralWidget(self.browser)
        self.showMaximized()

    def test(self):
        print('super')


app = QApplication(sys.argv)
QApplication.setApplicationName('Jello')
window = MainWindow()
app.exec_()

Do you have any idea of a solution for that? I've walked through many web pages without finding any lead.

Thanks!

like image 922
jauche Avatar asked Feb 12 '26 03:02

jauche


1 Answers

I had the same issue on Linux Manjaro KDE
the solution is to add '--no-sandbox' as a second item into QApplication() argument list like this:

app = QApplication(['', '--no-sandbox'])

so,
this code works fine:

from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5 import QtCore
app = QApplication(['', '--no-sandbox'])
main = QWebEngineView()
main.load(QtCore.QUrl(f"https://fast.com"))
main.show()
app.exec_()

enter image description here

but this one: does Not work:

from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5 import QtCore
app = QApplication([])
main = QWebEngineView()
main.load(QtCore.QUrl(f"https://fast.com"))
main.show()
app.exec_()

enter image description here

like image 154
ibrahem Avatar answered Feb 17 '26 19:02

ibrahem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!