Qt5.py enables you to write software that runs the same on both PySide2 and PyQt5.
See also
- Qt.py - Like Qt5.py, with added support for PySide and PyQt4.
Write once, run in any binding.
Qt5.py is the younger brother to Qt.py and provides extended support for features unique to Qt 5, such as QtQml, QtMultimedia and QtWebAssembly.
Goal | Description |
---|---|
Support co-existence | Qt5.py should not affect other bindings, not even Qt.py, running in the same interpreter session |
Build for one, run with all | Code written with Qt5.py should run identically on both PySide2 and PyQt5 |
Explicit is better than implicit | Differences between bindings should be visible to you. |
Qt5.py is a single file and can be either copy/pasted into your project, downloaded as-is, cloned as-is or installed via pip
.
# From PyPI
$ pip install Qt5.py
- Pro tip: The direct download and clone options refer to the latest commit of this project, which is typically beta. For the latest stable release, refer to any of the official releases
- Pro top: Qt5.py supports vendoring
Use Qt5.py as you would use PySide2.
import os
import sys
import tempfile
from Qt5 import QtGui, QtQml
f = tempfile.NamedTemporaryFile("w", delete=False)
f.write("""\
import QtQuick 2.4
import QtQuick.Controls 1.4
ApplicationWindow {
title: "My App"
width: 240
height: 180
visible: true
Button {
text: "Hello World"
anchors.centerIn: parent
}
}
""")
f.close()
app = QtGui.QGuiApplication(sys.argv)
engine = QtQml.QQmlApplicationEngine()
engine.load(f.name)
engine.quit.connect(app.quit)
app.exec_()
os.remove(f.name)