mottosso / Qt5.py

Minimal Python 2 & 3 shim around PySide2 and PyQt5
MIT License
33 stars 5 forks source link

Qt5.py enables you to write software that runs the same on both PySide2 and PyQt5.

See also


Goals

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.




Install

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




Usage

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)