PyQt6-WebEngine-Qt6
PyQt6-WebEngine-Qt6 is a supplementary package containing the essential subset of a Qt installation specifically required by PyQt6-WebEngine. It typically installs automatically as a dependency when a user installs PyQt6-WebEngine, which provides Python bindings for the Qt WebEngine framework. This framework enables embedding web content in applications using a Chromium-based engine. The current version is 6.11.0, and its release cadence generally aligns with updates to PyQt6 and the underlying Qt WebEngine.
Warnings
- breaking When migrating from PyQt5, the import structure for WebEngine classes has changed. Classes are now strictly separated into `PyQt6.QtWebEngineWidgets` (for widgets like `QWebEngineView`) and `PyQt6.QtWebEngineCore` (for core functionalities like `QWebEnginePage`, `QWebEngineProfile`). Direct imports from the main `PyQt6` namespace or `QtWidgets` for WebEngine components will fail.
- breaking Several Qt WebEngine API methods have moved or changed signatures in Qt 6. For example, `QWebEnginePage::print()` no longer takes a callback and has moved to `QWebEngineView::print()`, signalling completion with `QWebEngineView::printFinished()`. Similarly, `QWebEngineDownloadItem` has been renamed to `QWebEngineDownloadRequest` and moved to `QtWebEngineCore`.
- gotcha The method to start the application's event loop has changed from `app.exec_()` (used in older Python 2 compatible PyQt5 code) to `app.exec()` in PyQt6. While `app.exec()` is also available and preferred in modern PyQt5, using `app.exec_()` will raise an error in PyQt6.
- gotcha QWebEngineView does not automatically handle pop-up windows (e.g., those created by JavaScript `window.open()`). To support these, you must subclass `QWebEngineView` and reimplement its `createWindow()` method.
- gotcha Users have reported performance issues such as laggy scrolling and jerky videos with specific Qt WebEngine versions (e.g., Qt 6.7.0-1) on certain platforms, particularly Linux/X11, and sometimes involving specific GPU drivers. This may manifest as 'glitching' or 'Z-fighting'.
Install
-
pip install PyQt6-WebEngine
Imports
- QWebEngineView
from PyQt6.QtWebEngineWidgets import QWebEngineView
- QWebEnginePage
from PyQt6.QtWebEngineCore import QWebEnginePage
- QUrl
from PyQt6.QtCore import QUrl
Quickstart
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtCore import QUrl
class SimpleBrowser(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQt6 WebEngine Browser')
self.setGeometry(100, 100, 1024, 768)
layout = QVBoxLayout(self)
self.webview = QWebEngineView()
layout.addWidget(self.webview)
# Load a URL (e.g., Google or your own site)
self.webview.setUrl(QUrl('https://www.google.com'))
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
browser = SimpleBrowser()
browser.show()
sys.exit(app.exec())