简体   繁体   中英

Unable to render webpage using QWebEngineView

I've been trying to render a webpage onto a widget in PyQt5. These are my settings PyQt: 5.15.4 | PyQtWebEngine: 5.15.4 | PyQt5-tools 5.15.4.2

I'm trying to render out some basic websites like google.com but I'm facing a blank page.

self.google_lib_viewer= QtWebEngineWidgets.QWebEngineView(self.google_lib_tab)
self.google_lib_viewer.setGeometry(QtCore.QRect(0, 0, 656, 411))
self.google_lib_viewer.setObjectName("google_lib_viewer")
self.google_lib_viewer.load(QtCore.QUrl("https://google.com"))

But nothing seems to be visible.

I even tried to create a very normal webpage using PyQt5 but even that comes up blank. I tried uninstalling my PyQt5 packages and reinstalling them, but nothing seem to work. Can someone please help me out on this one!

I have separated the code into a separate code. Please use this for reproducing the issue.

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

app = QApplication(sys.argv)
web = QWebEngineView()

web.load(QUrl("http://google.com"))
web.show()

sys.exit(app.exec_())

I also find a small blink while the web page loads and it again disappears. I think something could be loading by getting closed soon

I had the exact same issue after upgrading from Ubuntu 20.04 to 22.04. This is how I solved it after hours of trial and error:

First, I checked with pip3 list which PyQt5 packages are installed and removed every single one of them (using pip3 uninstall... ,especially PyQt5-Qt5) and all of the PyQtWebEngine packages. Then, I installed PyQt5 version 5.15.6 and the webengine like this (the second is basically according to Carlos ):

     pip3 install PyQt5-Qt5==5.15.6
     sudo apt-get install -y python-pyqt5.qtwebengine 

This worked, at least for me. Hope it helps someone else...

web = QWebEngineView( widget name ) # You will write the name of the widget you created here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM