Created
September 6, 2024 09:26
-
-
Save 8Observer8/ce0e0c1d763158403f333e2b1cb8411b to your computer and use it in GitHub Desktop.
How to enable WebGL in QWebEngineView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
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__": | |
os.environ['QTWEBENGINE_CHROMIUM_FLAGS'] = '--use-gl=angle --gpu --gpu-launcher --in-process-gpu --ignore-gpu-blacklist --ignore-gpu-blocklist' | |
app = QApplication(sys.argv) | |
w = Widget() | |
w.show() | |
sys.exit(app.exec()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Topic on StackOverflow
Result for PyQt 6.7.0. It doesn't work:
Console log:
But when I have deleted everything that is related to
PyQt 6.7.0
andPyQt6-WebEngine
and I have installed PyQt 6.7.1 it works!