How to enable WebGL in QWebEngineView?
-
PyQt Version: 6.6.1
PySide Version: 6.6.1Hi,
I try to enable WebGL in QWebEngineView:
view.settings().setAttribute(QWebEngineSettings.WebAttribute.WebGLEnabled, True) view.setUrl(QUrl("https://get.webgl.org/"))
but it doesn't work:
import sys from PySide6.QtCore import QUrl from PySide6.QtWebEngineCore import QWebEngineSettings from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWidgets import QApplication, QVBoxLayout, QWidget class Widget(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QWebEngineView, PySide6, Python") self.resize(650, 400) layout = QVBoxLayout() view = QWebEngineView() layout.addWidget(view) self.setLayout(layout) # view.load(QUrl("file:///web-project/index.html")) view.settings().setAttribute(QWebEngineSettings.WebAttribute.WebGLEnabled, True) print("----------------------") print(view.settings().testAttribute(QWebEngineSettings.WebAttribute.WebGLEnabled)) view.setUrl(QUrl("https://get.webgl.org/")) if __name__ == "__main__": app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
Console output:
D3D11 smoke test failed (failed to create vertex shader) ---------------------- True doh set to "" -- SystemOnly D3D11 smoke test failed (failed to create vertex shader) js: Unrecognized Content-Security-Policy directive 'image-src'.
-
PyQt 6.6.1 behaves exactly the same way:
Console output:
D3D11 smoke test failed (failed to create vertex shader) ---------------------- True doh set to "" -- SystemOnly D3D11 smoke test failed (failed to create vertex shader) js: Unrecognized Content-Security-Policy directive 'image-src'.
import sys from PyQt6.QtCore import QUrl from PyQt6.QtWebEngineCore import QWebEngineSettings from PyQt6.QtWebEngineWidgets import QWebEngineView from PyQt6.QtWidgets import QApplication, QVBoxLayout, QWidget class Widget(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QWebEngineView, PyQt6, Python") self.resize(650, 400) layout = QVBoxLayout() view = QWebEngineView() layout.addWidget(view) self.setLayout(layout) # view.load(QUrl("file:///web-project/index.html")) view.settings().setAttribute(QWebEngineSettings.WebAttribute.WebGLEnabled, True) print("----------------------") print(view.settings().testAttribute(QWebEngineSettings.WebAttribute.WebGLEnabled)) view.setUrl(QUrl("https://get.webgl.org/")) if __name__ == "__main__": app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
PySide 6.1.1 includes WebEngine. For PyQt 6.1.1 the WebEngine must be installed using this command:
pip install PyQt6-WebEngine
-
I created a question on StackOverflow and added there some additional information: https://stackoverflow.com/questions/77690410/how-to-enable-webgl-in-qwebengineview
-
This is an answer of @ekhumoro from StackOverflow:
QTBUG-42182 is quite old, but the last comment there states: "The current status in Qt 5.5 is this: WebGL and accelerated Canvas work with OpenGL and are blacklisted unfortunately for ANGLE and software renderers due to thread synchronization issues with the former and performance issues with the latter.". This would seem to match your setup, but it's unclear whether it affects Qt6 or only applies to Qt5. Another issue is that none of the WebGL tests you did seems able to identify your GPU at all, which doesn't look promising...