Overview
PyQt6 6.0, released on January 6, 2021, is the Python binding for Qt 6. This major version brings changes to enumeration handling and aligns with the new Qt 6 architecture.
Main Features
Qt 6 migration
PyQt6 builds on Qt 6, which modernizes the graphics rendering pipeline, removes deprecated modules, and improves performance. Applications benefit from the new RHI (Rendering Hardware Interface) based rendering pipeline.
python
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt6.QtCore import Qt
app = QApplication(sys.argv)
window = QMainWindow()
window.setWindowTitle('PyQt6 - Hello')
window.setGeometry(100, 100, 400, 200)
label = QLabel('Welcome to PyQt6!', window)
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
window.setCentralWidget(label)
window.show()
sys.exit(app.exec())
Enum changes
Qt enumerations must now be referenced with their fully qualified name (scoped enums). For example, Qt.AlignCenter becomes Qt.AlignmentFlag.AlignCenter. This change improves code clarity but requires migration.
python
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QSizePolicy
# PyQt5: Qt.AlignCenter (unscoped)
# PyQt6: Qt.AlignmentFlag.AlignCenter (scoped)
# Enum migration examples
alignment = Qt.AlignmentFlag.AlignCenter
orientation = Qt.Orientation.Horizontal
key = Qt.Key.Key_Return
# Combining flags with the | operator
align = (Qt.AlignmentFlag.AlignHCenter
| Qt.AlignmentFlag.AlignTop)
# SizePolicy also scoped
policy = QSizePolicy(
QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Fixed
)
