This release is a pre-release and may not be stable for production use.
pyqtcompat
A single-module Qt binding compatibility layer for PyQt6, PySide6, PyQt5, PySide2, PyQt4, and PySide.
Installation
Install the package with:
pip install pyqtcompat
You must also have at least one supported Qt binding installed in your Python environment:
- PyQt6
- PySide6
- PyQt5
- PySide2
- PyQt4
- PySide
The module uses detect-qt-binding to choose the active binding.
Usage
Import the normalized Qt names from pyqtcompat instead of importing directly from a specific binding:
from pyqtcompat import QApplication, QLabel, QT_ALIGN_CENTER, execute
application = QApplication([])
label = QLabel('Hello from pyqtcompat')
label.setAlignment(QT_ALIGN_CENTER)
label.show()
raise SystemExit(execute(application))
Cross-binding window with a frameless, translucent, stay-on-top overlay:
from pyqtcompat import (
QApplication, QTextEdit, QRect, QRegion,
QT_FRAMELESS_WINDOW_HINT,
QT_WINDOW_STAYS_ON_TOP_HINT,
QT_WA_TRANSLUCENT_BACKGROUND,
QT_CROSS_CURSOR,
QT_LEFT_BUTTON,
QT_KEY_ESCAPE,
get_or_create_q_application,
execute,
)
application = get_or_create_q_application()
text_edit = QTextEdit()
text_edit.setWindowFlags(
QT_FRAMELESS_WINDOW_HINT | QT_WINDOW_STAYS_ON_TOP_HINT
)
text_edit.setAttribute(QT_WA_TRANSLUCENT_BACKGROUND)
text_edit.setCursor(QT_CROSS_CURSOR)
# Check button or key presses against QT_LEFT_BUTTON / QT_KEY_ESCAPE as needed
text_edit.show()
raise SystemExit(execute(application))
You can also inspect which binding was selected:
from pyqtcompat import QT_BINDING
print(QT_BINDING)
Public API
pyqtcompat defines __all__ at the top of the module. These names are the intended application-facing imports.
Binding and module-level names:
QtBindingsQT_BINDINGIS_PYQT,IS_PYSIDE,IS_QT6QtSignal
Common Qt classes exported directly:
QTimerQImage,QPixmap,QColor,QPainter,QPen,QScreenQRect,QRegionQAbstractSliderQApplicationQCheckBox,QComboBox,QDesktopServices,QDesktopWidget,QFileDialogQFrame,QGroupBox,QHBoxLayout,QLabel,QLineEditQMainWindow,QMessageBox,QPushButton,QScrollAreaQSizePolicy,QSlider,QTextEdit,QVBoxLayout,QWidget
Compatibility constants exported directly:
Format_RGB32,Format_ARGB32,Format_RGB888QT_KEEP_ASPECT_RATIO,QT_SMOOTH_TRANSFORMATION,QT_ALIGN_CENTER,QT_HORIZONTALQT_SCROLLBAR_ALWAYS_OFF,QT_SCROLLBAR_AS_NEEDEDQSIZEPOLICY_EXPANDINGQT_FRAMELESS_WINDOW_HINT,QT_WINDOW_STAYS_ON_TOP_HINT,QT_WA_TRANSLUCENT_BACKGROUNDQT_CROSS_CURSOR,QT_LEFT_BUTTON,QT_KEY_ESCAPESLIDER_SINGLE_STEP_ADD,SLIDER_SINGLE_STEP_SUB,SLIDER_PAGE_STEP_ADD,SLIDER_PAGE_STEP_SUB,SLIDER_MOVE
Helper functions exported directly:
exec_qapplication(app)- Purpose: Run the Qt application event loop with the correct cross-binding call style.
- Returns: the integer exit code returned by the event loop.
execute(q_application)- Purpose: Alias for
exec_qapplication()for codebases already using that name. - Returns: the integer exit code returned by the event loop.
- Purpose: Alias for
get_or_create_q_application(argv=None)- Purpose: Return the existing
QApplicationinstance, or create one if none exists yet. - Returns: a
QApplicationinstance.
- Purpose: Return the existing
get_buffer(qimage)- Purpose: Return a Python buffer-compatible view of the pixel memory of a
QImage, handling PyQt/PySide differences. - Returns: a binding-specific buffer object suitable for zero-copy access.
- Purpose: Return a Python buffer-compatible view of the pixel memory of a
qimage_get_buffer(qimage)- Purpose: Same as
get_buffer(); provided as the explicitQImage-named form. - Returns: a binding-specific buffer object suitable for zero-copy access.
- Purpose: Same as
get_primary_screen_geometry()- Purpose: Read the geometry of the primary screen using the correct API for old and new Qt bindings.
- Returns: a Qt rectangle object describing the primary screen bounds.
get_primary_screen_size()- Purpose: Get the primary screen width and height as plain Python values.
- Returns: a
(width, height)tuple of integers.
grab_primary_screen_pixmap()- Purpose: Capture the full primary screen into a pixmap using the correct API for the active binding.
- Returns: a
QPixmapcontaining the screen capture.
Example using QImage buffer access:
from pyqtcompat import QImage, Format_RGB32, get_buffer
image = QImage(64, 64, Format_RGB32)
buffer_object = get_buffer(image)
print(type(buffer_object))
Example using screen-grab helpers:
from pyqtcompat import get_or_create_q_application, get_primary_screen_size, grab_primary_screen_pixmap
application = get_or_create_q_application()
width, height = get_primary_screen_size()
pixmap = grab_primary_screen_pixmap()
print(width, height, pixmap.width(), pixmap.height())
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Metadata
Release files for pyqtcompat 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyqtcompat-0.1.0a1.tar.gz | 6.4 kB | Without provenance | Details for pyqtcompat-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyqtcompat-0.1.0a1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pyqtcompat-0.1.0a1-py2.py3-none-any.whl |
Total release size: 13.2 kB
Release files / pyqtcompat-0.1.0a1.tar.gz
| Download URL | pyqtcompat-0.1.0a1.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f22f0f541b64be3dad9daa63caa581df249ab3089266685a16327fe000a2bd41
|
|
BLAKE2b-256 checksum How to use checksums |
4a23ee6d373169734305903deecfb0b826fd1fa8167efba46609d7beeab14362
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / pyqtcompat-0.1.0a1-py2.py3-none-any.whl
| Download URL | pyqtcompat-0.1.0a1-py2.py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
dbe370b9c8fb34b91345c51a5deb9727fb1f48705d7e99f1f955e478d6e5b3e4
|
|
BLAKE2b-256 checksum How to use checksums |
914480e0358614617d1d0e66c7bf8bcdba49281c59f3f8331f6a88c45954c423
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Security for pyqtcompat 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.