### Run Example from Directory Source: https://github.com/mottosso/qt.py/blob/master/examples/QtSiteConfig_platforms/README.md Navigate to the example directory and run the main script. This ensures QtSiteConfig.py is importable. ```bash cd to/this/directory python main.py # Qt.QtCore was successfully removed by QSiteConfig.py ``` -------------------------------- ### Install Qt.py Source: https://github.com/mottosso/qt.py/blob/master/CONTRIBUTING.md Use this command to install the Qt.py package. Ensure you have pip installed. ```bash $ pip install Qt.py ``` -------------------------------- ### Basic Qt.py Application Example Source: https://github.com/mottosso/qt.py/blob/master/README.md A simple example demonstrating how to create a Qt application with a button using Qt.py. ```python import sys from Qt import QtWidgets, QtCompat app = QtWidgets.QApplication(sys.argv) button = QtWidgets.QPushButton("Hello World") button.show() QtCompat.QApplication.exec_() ``` -------------------------------- ### Install Qt.py via pip Source: https://github.com/mottosso/qt.py/blob/master/README.md Install the Qt.py library from the Python Package Index using pip. ```bash pip install Qt.py ``` -------------------------------- ### Install Qt.py via conda Source: https://github.com/mottosso/qt.py/blob/master/README.md Install the Qt.py library from the conda-forge channel using conda. ```bash conda config --add channels conda-forge conda install qt.py ``` -------------------------------- ### QtCompat HeaderView Example Source: https://github.com/mottosso/qt.py/blob/master/README.md Example of using QtCompat to control header view properties like movability, ensuring cross-binding compatibility. ```python from Qt import QtCore, QtWidgets, QtCompat header = QtWidgets.QHeaderView(QtCore.Qt.Horizontal) QtCompat.QHeaderView.setSectionsMovable(header, False) movable = QtCompat.QHeaderView.sectionsMovable(header) ``` -------------------------------- ### Run Example with PYTHONPATH Source: https://github.com/mottosso/qt.py/blob/master/examples/QtSiteConfig_platforms/README.md Set the PYTHONPATH environment variable to include the directory containing QtSiteConfig.py, then run the main script. This is useful when running from a different directory. ```bash set PYTHONPATH=path/to/QtSiteConfig/ python main.py # Qt.QtCore was successfully removed by QSiteConfig.py ``` -------------------------------- ### Set Preferred Bindings with JSON and Fallback Source: https://github.com/mottosso/qt.py/blob/master/README.md This example demonstrates setting preferred bindings for the 'Qt' namespace using JSON, while also providing a default binding for all other Qt modules via QT_PREFERRED_BINDING. ```bash # Try PyQt6 first and then PyQt5 for the Qt module name space. $ export QT_PREFERRED_BINDING_JSON="{"Qt":["PyQt6","PyQt5"]}" # Use PySide2 for any other Qt module name spaces. $ export QT_PREFERRED_BINDING=PySide2 ``` -------------------------------- ### Get Qt.py Binding Information Source: https://github.com/mottosso/qt.py/blob/master/README.md Retrieve the name of the currently used Qt binding (e.g., PyQt5) and the Qt version. ```python >>> from Qt import __binding__ >>> __binding__ 'PyQt5' ``` -------------------------------- ### Set Multiple Preferred Qt Bindings Source: https://github.com/mottosso/qt.py/blob/master/README.md You can specify a prioritized list of preferred bindings by separating them with a colon (Unix/OSX) or semicolon (Windows). This example attempts to use PyQt5 first, then PySide2. ```bash # Try PyQt5 first and then PySide2, but nothing else. $ export QT_PREFERRED_BINDING=PyQt5:PySide2 ``` -------------------------------- ### Set Preferred Qt Binding (Windows) Source: https://github.com/mottosso/qt.py/blob/master/README.md On Windows, use the 'set' command to specify the preferred Qt binding. This influences which binding Qt.py will attempt to use first. The example sets PyQt5 as the preferred binding. ```bash $ set QT_PREFERRED_BINDING=PyQt5 # Windows ``` -------------------------------- ### Using QApplication.instance() as qApp alternative (PySide2) Source: https://github.com/mottosso/qt.py/blob/master/CAVEATS.md Demonstrates the recommended workaround for accessing the current QApplication instance, using QApplication.instance() instead of the unavailable qApp. ```python # PySide2 >>> from Qt import QtWidgets >>> app = QtWidgets.QApplication(sys.argv) >>> app == QtWidgets.QApplication.instance() True ``` -------------------------------- ### Example Tox Test Output Source: https://github.com/mottosso/qt.py/blob/master/README.md A sample of the output generated by tox when running tests, showing the status and duration of various test suites. ```text membership-begin: OK (0.16=setup[0.06]+cmd[0.09] seconds) membership-py39-PySide5.15: OK (0.38=setup[0.02]+cmd[0.36] seconds) membership-py39-PyQt5.15: OK (0.28=setup[0.02]+cmd[0.27] seconds) membership-py311-PySide6.5: OK (0.67=setup[0.08]+cmd[0.59] seconds) membership-py311-PyQt6.7: OK (0.42=setup[0.14]+cmd[0.28] seconds) membership-end: OK (0.17=setup[0.00]+cmd[0.17] seconds) test-begin: OK (0.06=setup[0.00]+cmd[0.06] seconds) test-py37-PySide5.13-impl: OK (11.03=setup[5.59]+cmd[1.22,4.22] seconds) test-py37-PySide5.13-caveats: OK (7.05=setup[5.64]+cmd[1.17,0.24] seconds) test-py37-PySide5.13-examples: OK (7.78=setup[5.61]+cmd[1.20,0.61,0.36] seconds) ... test-py311-PyQt6.5-impl: OK (9.45=setup[6.81]+cmd[2.64] seconds) test-py311-PyQt6.5-caveats: OK (7.09=setup[6.80]+cmd[0.30] seconds) test-py311-PyQt6.5-examples: OK (7.86=setup[6.81]+cmd[0.72,0.33] seconds) congratulations :) (13.30 seconds) ``` -------------------------------- ### Access QtCompat Module Source: https://github.com/mottosso/qt.py/blob/master/README.md Demonstrates how to access the QtCompat module, which provides compatibility wrappers for Qt functionality. ```python >>> from Qt import QtCompat >>> QtCompat.loadUi ``` -------------------------------- ### Commit Message Examples Source: https://github.com/mottosso/qt.py/blob/master/CONTRIBUTING.md Follow the imperative, present-tense style for commit messages. This makes it clear what action the commit will perform when applied to a branch. ```bash # No Changed this and did that # No Changes this and does that # Yes Change this and do that ``` -------------------------------- ### Modify Qt.py Members at Run-time Source: https://github.com/mottosso/qt.py/blob/master/README.md Create a QtSiteConfig.py file to dynamically add or remove members from Qt.py's exposed modules. This example shows how to remove the QtCore module. ```python # QtSiteConfig.py def update_members(members): """Called by Qt.py at run-time to modify the modules it makes available. Arguments: members (dict): The members considered by Qt.py """ members.pop("QtCore") ``` -------------------------------- ### Load UI File with Qt.py Source: https://github.com/mottosso/qt.py/blob/master/README.md Use `QtCompat.loadUi` to load .ui files. This function abstracts the differences between PyQt and PySide implementations. ```python import sys from Qt import QtCompat, QtWidgets app = QtWidgets.QApplication(sys.argv) u = QtCompat.loadUi(uifile="my.ui") u.show() QtCompat.QApplication.exec_() ``` -------------------------------- ### Set Preferred Qt Binding (Unix/OSX) Source: https://github.com/mottosso/qt.py/blob/master/README.md On Unix-like systems (Linux, macOS), use the 'export' command to set the QT_PREFERRED_BINDING environment variable. This example configures PyQt5 as the preferred binding. ```bash $ export QT_PREFERRED_BINDING=PyQt5 # Unix/OSX ``` -------------------------------- ### Load UI File onto Existing Widget Source: https://github.com/mottosso/qt.py/blob/master/README.md The `baseinstance` argument allows loading a UI file onto an existing widget. Ensure `baseinstance` is of the correct type (e.g., `QMainWindow` for a `QMainWindow` UI). ```python QtCompat.loadUi(uifile="my.ui", baseinstance=QtWidgets.QWidget) ```