[QGIS-Developer] Transition from QtWebKit to QtWebEngine in qgis2web (QGIS plugin)

Jan Dalheimer jan at dalheimer.de
Mon Jul 8 13:25:35 PDT 2024


Hi!

I have not got access to a system to actually try my answers so some of 
them are educated speculation, but hopefully they'll help you in the 
right direction anyway:

* Have you tried if the python3-pyqtwebengine package in the 
OSGeo4W-installer installs the required dependency?
* (question 1) It's still (while on Qt 5) possible to build QtWebKit 
from source, as the OSGeo4W-packagers seem to have done for you: 
https://download.osgeo.org/osgeo4w/v2/x86_64/release/qt5/qtwebkit/
* (question 2) QtWebEngine is essentially a repackaged and slightly 
adapted Chromium; the same engine that powers the Chrome browser. That 
means installing QtWebEngine pulls in almost as much code as installing 
another browser, the same happens for QtWebKit (which is a repackaging 
of the WebKit browser engine). So if both would be installed by default 
then users would essentially get two additional browsers taking up space 
on their system
* (question 3) qgis.PyQt does not export everything from PyQt{version}, 
but only what is specified by QGIS 
(https://github.com/qgis/QGIS/blob/final-3_36_3/python/PyQt/CMakeLists.txt). 
In 3.36 this does not include QtWebEngineWidgets, however in 3.38 it 
does (which makes me assume that installing QGIS 3.38 through OSGeo4W 
will also pull in QtWebEngine automatically as you've requested).

Regards,
Jan Dalheimer


------ Original Message ------
>From "Andrea Ordonselli via QGIS-Developer" 
<qgis-developer at lists.osgeo.org>
To qgis-developer at lists.osgeo.org
Date 2024-07-08 13:55:30
Subject [QGIS-Developer] Transition from QtWebKit to QtWebEngine in 
qgis2web (QGIS plugin)

>Dear QGIS Developers,
>
>I am currently maintaining the qgis2web plugin and am in the process of 
>phasing out QtWebKit due to its obsolescence and inability to handle 
>modern code.
>
>qgis2web utilizes QtWebKit to display its export in a web preview 
>window, which reads the exported project comprising HTML, JS, and CSS 
>files. Without updating QtWebKit, I cannot update the third-party 
>libraries used in the export (e.g., ol-geocoder, ol-layerswitcher, and 
>many others).
>
>I've found numerous unresolved discussions about QtWebEngine online, 
>but they haven't helped me achieve my goal.
>
>Here is my current setup:
>
>Windows 10
>Standard QGIS installation (not OSGeo4W), version: 3.36.3-Maidenhead
>PyQt version: 5.15.10
>Qt version: 5.15.13
>Progress so far:
>
>Using "Qt Designer," dragging the "QWebEngineView" element into the 
>plugin design causes the program to freeze. This issue is resolved 
>after installing the dependency in the next step.
>The standard installation via .msi lacks the QtWebEngine dependency, so 
>I had to install it manually. This is a significant obstacle: I believe 
>most QGIS users install the software on Windows using the .msi package, 
>so I will need to provide a guide or come up with a solution for 
>installation through the plugin itself. In any case, I installed the 
>dependency by opening the "OSGeo4W Shell" and running the command:
>
>python -m pip install PyQtWebEngine
>
>Then, using
>
>pip list
>
>I confirmed the dependencies are now:
>
>PyQtWebEngine 5.15.6
>PyQtWebEngine-Qt5 5.15.2
>At this point, I was able to write the following Python code and 
>receive a positive output
>
>try:
>     from PyQt5.QtWebEngineWidgets import QWebEngineView, 
>QWebEngineProfile, QWebEnginePage, QWebEngineSettings
>     webengine_available = True
>     print("QtWebEngine available")
>except ImportError as e:
>     webengine_available = False
>     print("QtWebEngine not available:", e)
>In "Qt Designer" I can now add the "QWebEngineView" element without 
>issues, and if I set a website manually by configuring the URL in the 
>"QWebEngineView" section, it displays perfectly.
>Where I am stuck:
>
>Writing from qgis.PyQt.QtWebEngineWidgets results in an error.
>Whether I add the "QWebEngineView" element manually in "Qt Designer" or 
>via Python, the result is a completely blank plugin screen. The code I 
>am testing for insertion is as follows:
>
>if webengine_available:
>     print("WebEngine is available. Initializing QWebEngineView...")
>     widget = QWebEngineView()
>     self.preview = widget
>     try:
>         self.preview.setUrl(QUrl("https://opengis.it"))
>         print("Loading opengis.it in QWebEngineView.")
>     except Exception as e:
>         print("Failed to set URL:", e)
>else:
>     print("WebEngine is not available. Initializing QTextBrowser...")
>     widget = QTextBrowser()
>     widget.setText(self.tr('Preview is not available since QtWebEngine 
>dependency is missing on your system'))
>     print("QTextBrowser initialized with fallback message.")
>
>self.right_layout.insertWidget(0, widget)
>print("Widget inserted into right_layout.")
>Questions:
>
>Since QtWebKit was deprecated in Qt 5.6, why does it still work in 
>version 5.15.13?
>Why isn't the QtWebEngine dependency included by default in the .msi 
>installation?
>Why doesn't from qgis.PyQt.QtWebEngineWidgets work?
>Why is there a discrepancy between what I see and configure in "Qt 
>Designer" and what appears when I run the plugin in QGIS (specifically, 
>a completely blank screen)?
>Current Status:
>
>I have no errors in the QGIS Python console, only positive prints, but 
>I cannot get past the blank plugin screen when launched in QGIS.
>
>Thank you all for your valuable work, which allows me to perform my 
>beloved job.
>
>Best regards
>
>Andrea Ordonselli
>OpenGIS.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240708/4c6956a6/attachment.htm>


More information about the QGIS-Developer mailing list