{"id":2707,"library":"pyqt5","title":"PyQt5","description":"PyQt5 is a comprehensive set of Python bindings for the Qt cross-platform application toolkit, enabling developers to create graphical user interfaces (GUIs) for desktop and mobile systems. It leverages the robust C++ Qt framework, providing high-level APIs for UI development, multimedia, networking, databases, and more. The current stable version is 5.15.11, maintained by Riverbank Computing Ltd. While PyQt5 is mature and stable, its successor, PyQt6, is available, targeting Qt6.","status":"active","version":"5.15.11","language":"en","source_language":"en","source_url":"https://www.riverbankcomputing.com/software/pyqt/","tags":["GUI","desktop","Qt","bindings","UI","cross-platform"],"install":[{"cmd":"pip install PyQt5","lang":"bash","label":"Install PyQt5"}],"dependencies":[{"reason":"PyQt5 is a binding for the C++ Qt5 toolkit, which is the underlying GUI framework. While pip handles binary distribution for common OSes, the core Qt5 libraries are fundamental.","package":"qt5-base","optional":false},{"reason":"Provides development tools like Qt Designer, which are not included in the main PyQt5 wheel package.","package":"pyqt5-tools","optional":true},{"reason":"SIP is a tool that generates the Python bindings for C++ libraries. It is a fundamental component for PyQt5's operation, often bundled implicitly with wheel installations but explicit for source builds or certain Linux distributions.","package":"python-pyqt5-sip","optional":false}],"imports":[{"symbol":"QApplication","correct":"from PyQt5.QtWidgets import QApplication"},{"symbol":"QWidget","correct":"from PyQt5.QtWidgets import QWidget"},{"symbol":"QLabel","correct":"from PyQt5.QtWidgets import QLabel"},{"symbol":"QPushButton","correct":"from PyQt5.QtWidgets import QPushButton"},{"symbol":"QVBoxLayout","correct":"from PyQt5.QtWidgets import QVBoxLayout"},{"note":"Qt core enums (like alignment flags, key codes) are typically found in QtCore.Qt, not QtGui.","wrong":"from PyQt5.QtGui import Qt","symbol":"Qt","correct":"from PyQt5.QtCore import Qt"}],"quickstart":{"code":"import sys\nfrom PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout\nfrom PyQt5.QtCore import Qt\n\nclass MyWindow(QWidget):\n    def __init__(self):\n        super().__init__()\n        self.setWindowTitle('PyQt5 Hello World')\n        self.setGeometry(100, 100, 400, 200) # x, y, width, height\n\n        layout = QVBoxLayout()\n        self.label = QLabel('Hello, PyQt5!', self)\n        self.label.setAlignment(Qt.AlignCenter)\n        self.label.setStyleSheet(\"font-size: 24px; color: blue;\")\n\n        layout.addWidget(self.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_())\n","lang":"python","description":"This quickstart creates a simple PyQt5 window displaying 'Hello, PyQt5!' in a centrally aligned label. It demonstrates the basic structure of a PyQt5 application, including creating an QApplication instance, defining a main window (subclassing QWidget), adding a QLabel, setting layout, and starting the application's event loop."},"warnings":[{"fix":"Always use `app.exec_()` for QApplication and dialogs in PyQt5 to ensure compatibility across various minor versions and to distinguish it from Python's keyword.","message":"The `exec()` method on QApplication and QDialog instances was renamed to `exec_()` in PyQt5 (and earlier versions targeting Python 2) to avoid conflicts with Python's `exec` keyword. While `exec()` works in PyQt5 for Python 3, `exec_()` is the widely adopted and safer convention for PyQt5 applications. In PyQt6, it reverted to `exec()`.","severity":"breaking","affected_versions":"All PyQt5 versions (for Python 3), especially when migrating from older code or considering PyQt6."},{"fix":"Install `pyqt5-tools` separately: `pip install pyqt5-tools~=5.15`. You can then find `designer.exe` (or equivalent) in your virtual environment's `Scripts` (Windows) or `bin` (Linux/macOS) directory.","message":"Development tools like Qt Designer (`designer.exe`), `pyuic5`, and `pyrcc5` are no longer included directly with the `PyQt5` wheel installation. They are provided in a separate package, `pyqt5-tools`.","severity":"gotcha","affected_versions":"PyQt5 5.15.x and later, where these tools are separated."},{"fix":"Update signal/slot connections to the 'new-style' Python callable syntax (e.g., `button.clicked.connect(self.my_slot)`). Adjust imports to reflect the new module structure for GUI elements.","message":"Migration from PyQt4 to PyQt5 involves significant breaking changes, notably the removal of the 'old-style' `QObject.connect()` signal/slot syntax and the re-organization of classes from the `QtGui` module into `QtGui`, `QtWidgets`, and `QtPrintSupport` modules.","severity":"breaking","affected_versions":"All PyQt5 versions when porting from PyQt4."},{"fix":"For new projects, evaluate PyQt6. If sticking with PyQt5, be aware of migration paths and potential differences if examples/tutorials from PyQt6 are encountered. PyQt5 supports fully qualified enum names which helps with future compatibility.","message":"With the release of PyQt6 (targeting Qt6), PyQt5 is considered a mature but older generation. While PyQt5 is still actively maintained, new projects are often encouraged to start with PyQt6 for modern features, better performance, and long-term support. There are differences in enum naming (fully qualified names in PyQt6), module organization (e.g., `QAction` moved), and High DPI scaling defaults.","severity":"gotcha","affected_versions":"All PyQt5 users, particularly those starting new projects or considering future upgrades."},{"fix":"Familiarize yourself with common C++ to Python binding patterns (e.g., `const QString&` in C++ often translates to `str` in Python). Utilize community tutorials and examples specific to PyQt5.","message":"Official PyQt5 documentation often links to the C++ Qt documentation. This means users may need to infer Python equivalents from C++ signatures and concepts, which can be a learning curve for those unfamiliar with C++.","severity":"gotcha","affected_versions":"All PyQt5 versions."}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}