The Qt Team recently posted that Qt will now be officially supporting the PySide2 project, which they are calling “Qt for Python”. It will be a complete port of the original PySide, which only supported Qt 4. PySide2 supports Qt 5. Qt for Python will have the following license types: GPL, LGPL and commercial.
PySide2 supports Python 2.7 as well as Python 3.4 – 3.6. There are snapshot wheel builds available here.Let’s say we downloaded the Windows Python wheel. To install it, you can use pip like this:
python -m pip install PySide2-5.11.0a1-5.11.0-cp36-cp36m-win_amd64.whl
Once you have PySide2 installed, we can get started by looking at a really simple example:
import sys from PySide2.QtWidgets import QApplication, QLabel if __name__ == '__main__': app = QApplication() label = QLabel("Qt for Python!") label.show() sys.exit(app.exec_())
This code will create our application object (QApplication) and a QLabel to go on it. When you run app.exec_(), you start PySide2’s event loop. Since we do not specify a size for the label or the application, the size of the application defaults to be just large enough to fit the label on-screen: