{"id":1661,"library":"pyqt6","title":"PyQt6","description":"PyQt6 provides Python bindings for the Qt cross-platform application development framework, allowing developers to create desktop applications with native look and feel. It is currently at version 6.11.0 and typically releases new versions in close alignment with the major and minor releases of the underlying Qt library.","status":"active","version":"6.11.0","language":"en","source_language":"en","source_url":"https://www.riverbankcomputing.com/software/pyqt/intro","tags":["GUI","Qt","desktop","widgets"],"install":[{"cmd":"pip install PyQt6","lang":"bash","label":"Install PyQt6"}],"dependencies":[],"imports":[{"symbol":"QApplication","correct":"from PyQt6.QtWidgets import QApplication"},{"symbol":"QWidget","correct":"from PyQt6.QtWidgets import QWidget"},{"symbol":"QLabel","correct":"from PyQt6.QtWidgets import QLabel"},{"symbol":"QVBoxLayout","correct":"from PyQt6.QtWidgets import QVBoxLayout"},{"note":"While some Qt enums were accessible via QtWidgets in PyQt5, PyQt6 enforces stricter module separation. Core enums like AlignmentFlag are in QtCore.","wrong":"from PyQt6.QtWidgets import Qt","symbol":"Qt","correct":"from PyQt6.QtCore import Qt"}],"quickstart":{"code":"import sys\nfrom PyQt6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout\nfrom PyQt6.QtCore import Qt\n\nclass MyWindow(QWidget):\n    def __init__(self):\n        super().__init__()\n        self.setWindowTitle(\"My PyQt6 App\")\n        self.setGeometry(100, 100, 400, 200)\n\n        layout = QVBoxLayout()\n        label = QLabel(\"Hello, PyQt6!\", self)\n        label.setAlignment(Qt.AlignmentFlag.AlignCenter)\n        layout.addWidget(label)\n        self.setLayout(layout)\n\nif __name__ == \"__main__\":\n    app = QApplication(sys.argv)\n    window = MyWindow()\n    window.show()\n    sys.exit(app.exec())","lang":"python","description":"This quickstart creates a simple desktop application window with a 'Hello, PyQt6!' label centered within it. It demonstrates the basic structure of a PyQt6 application, including `QApplication` instantiation, creating a `QWidget`, using a layout, and running the event loop."},"warnings":[{"fix":"Update all enum references to use the specific enum class (e.g., `Qt.AlignmentFlag.AlignCenter` instead of `Qt.AlignCenter`). Refer to the PyQt6 documentation for the correct enum types.","message":"Enum values (like `Qt.AlignRight`) must now be accessed via explicit enum types (e.g., `Qt.AlignmentFlag.AlignRight`, `Qt.ItemFlag.Selectable`). Direct access via `Qt.` is deprecated or removed in PyQt6.","severity":"breaking","affected_versions":"6.0.0 onwards (when migrating from PyQt5)"},{"fix":"Ensure `QApplication` is instantiated only once. In test environments or complex applications, check for an existing instance using `QApplication.instance()` before creating a new one: `app = QApplication.instance() or QApplication(sys.argv)`.","message":"The `QApplication` instance must be a singleton. Attempting to create a second `QApplication` will raise a `RuntimeError` (`RuntimeError: Application.instance() must be called before QApplication constructor`).","severity":"breaking","affected_versions":"All PyQt6 versions"},{"fix":"Offload intensive computations or I/O operations to separate threads using `QThread` or Python's `threading`/`multiprocessing` modules. Use Qt's signal/slot mechanism to communicate results back to the GUI thread for UI updates.","message":"Performing long-running or blocking operations directly on the main GUI thread will freeze your application's user interface, making it unresponsive.","severity":"gotcha","affected_versions":"All PyQt6 versions"},{"fix":"Always assign a parent to widgets where appropriate (e.g., `QLabel('Text', parent=self)`). For objects without a parent, explicitly manage their lifecycle or ensure they are properly referenced to prevent Python's garbage collector from deleting them prematurely if they are still needed by Qt.","message":"PyQt6 (Qt) objects have a parent-child ownership model. If an object has a parent, it is automatically deleted when its parent is deleted. Misunderstanding this can lead to memory leaks (orphaned objects without parents) or premature object deletion.","severity":"gotcha","affected_versions":"All PyQt6 versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}