[QGIS-Developer] QGIS-Developer Digest, Vol 225, Issue 6
Jean-Baptiste Peter
jbpeter at outlook.com
Tue Jul 9 02:17:00 PDT 2024
Dear Andreas,
I have been playing with QWebEngineView for a while and managed to get it to work using the recently updated default libs of Osgeo4W and the following code:
https://github.com/jbp35/layer-atlas-plugin/blob/main/Layer_Atlas_dockwidget.py
>From my understanding, two things still have to be addressed in order to ensure that it works in all cases on windows (I am not able to test on other platforms) :
- The .msi installer for windows needs to be upgraded to include PyQtWebEngine module version >= 5.15.6 (older versions won't work)
- SIP binding needs to be added in order to be able to import QWebChannel class from python console (this class is used to establish a bridge between python and HTML/JavaScript)
Best,
--
Jean-Baptiste PETER
Project Manager
Atelier Alfred Peter
+33 (0)3 88 22 78 25
-----Original Message-----
From: QGIS-Developer <qgis-developer-bounces at lists.osgeo.org> On Behalf Of qgis-developer-request at lists.osgeo.org
Sent: Monday, July 8, 2024 9:00 PM
To: qgis-developer at lists.osgeo.org
Subject: QGIS-Developer Digest, Vol 225, Issue 6
Send QGIS-Developer mailing list submissions to
qgis-developer at lists.osgeo.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.osgeo.org/mailman/listinfo/qgis-developer
or, via email, send a message with subject or body 'help' to
qgis-developer-request at lists.osgeo.org
You can reach the person managing the list at
qgis-developer-owner at lists.osgeo.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of QGIS-Developer digest..."
Today's Topics:
1. Transition from QtWebKit to QtWebEngine in qgis2web (QGIS
plugin) (info at opengis.it)
----------------------------------------------------------------------
Message: 1
Date: Mon, 8 Jul 2024 13:55:30 +0200
From: info at opengis.it
To: qgis-developer at lists.osgeo.org
Subject: [QGIS-Developer] Transition from QtWebKit to QtWebEngine in
qgis2web (QGIS plugin)
Message-ID: <SGAZSI$30D172754494A36ADC025D0FF69D7794 at opengis.it>
Content-Type: text/plain; charset="utf-8"
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:
1. 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.
2. 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
3. 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)
4. 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:
1. Writing from qgis.PyQt.QtWebEngineWidgets results in an error.
2. 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:
1. Since QtWebKit was deprecated in Qt 5.6, why does it still work in version 5.15.13?
2. Why isn't the QtWebEngine dependency included by default in the .msi installation?
3. Why doesn't from qgis.PyQt.QtWebEngineWidgets work?
4. 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/2807eb32/attachment-0001.htm>
------------------------------
Subject: Digest Footer
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
------------------------------
End of QGIS-Developer Digest, Vol 225, Issue 6
**********************************************
More information about the QGIS-Developer
mailing list