For internal and external distribution
(Slide updated on 08.12.2023)
pyside6-uic, pyside6-rcc,
pyside6-designer
etc.shiboken_generator
is GPLv3*.so, *.dll, *.dylib
)QtOpcUa, QtMqtt, QtCoAp
).whl files
)
βͺοΈPySide6
βββ Qt modules β
βββ pyside6-designer β
βββ pyside6-rcc β
βββ pyside6-uic β
βββ ...tools β
βͺοΈShiboken6 (module)
βββ shiboken6 β
βͺοΈShiboken6_Generator (exe)
βββ shiboken6 β
shiboken6_generator
$ pip install shiboken6_generator
$ python setup.py install
# there are many other options!
doc.qt.io/qtforpython/gettingstarted.html
$ pip install shiboken6-xxxx.whl \
pyside6-essentials-xxxx.whl \
pyside6-addons-xxxx.whl
(xxxx contains information about architecture, OS and the PySide, Qt, and Python versions)
$ cd /path/to/Qt/QtForPython/6.6.1
$ pip install -r requirements.txt
# The txt file contains the info
# for all the packages next to them.
$ pip install qtpip
$ qtpip install pyside6
βͺοΈPySide6
βββ Qt modules β
βββ pyside6-designer β
βββ pyside6-rcc β
βββ pyside6-uic β
βββ ...tools β
βββ shiboken-wizard β
π
βͺοΈShiboken6 (module)
βββ shiboken6 β
βͺοΈShiboken6_Generator (exe)
βββ shiboken6 β
βͺοΈPySide6
βββ Qt modules β
βββ Qt M2M Protocols β
π
βββ pyside6-designer β
βββ pyside6-rcc β
βββ pyside6-uic β
βββ ...tools β
βββ shiboken-wizard β
π
βͺοΈShiboken6 (module)
βββ shiboken6 β
βͺοΈShiboken6_Generator (exe)
βββ shiboken6 β
int a = 1;
float b = 4.3;
string c = "hello";
a = 1
b = 4.3
c = "hello"
$ g++ main.cpp -o main
$ ./main
$ # no compilation
$ python main.py
QObject *obj = new QObject(...);
delete obj;
obj = QObject(...)
del obj # Optional
#include <iostream>
int main(int argc, char *argv[]) {
std::cout << "Hello World" << endl;
}
print("Hello World")
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
private slots:
void handleButton();
private:
QPushButton *m_button;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
m_button = new QPushButton("My Button", this);
connect(m_button, SIGNAL(clicked()), this, SLOT(handleButton()));
}
void MainWindow::handleButton()
{
m_button->setText("Ready");
}
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return app.exec(d);
}
import sys
from pyside6.QtWidgets import QApplication, QMainWindow, QPushButton
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.button = QPushButton("My Button", self)
self.button.clicked.connect(self.handleButton)
def handleButton(self):
self.button.setText("Ready")
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec())
Checked on 6.6
Core | D-Bus | GUI | Network |
QML | Quick | Quick Controls | Quick Dialogs |
Quick Layouts | Quick Test | Test | Widgets |
Some modules could be incomplete, please see wiki.qt.io/Qt_for_Python_Missing_Bindings for more information.
Active Qt | 3D | Bluetooth | Concurrent |
Help | Image Formats | Multimedia | NFC |
OPC UA | OpenGL | Positioning | |
Print Support | Quick Widgets | Quick Effects | Quick Particles |
Remote Objects | SCXML | Sensors | Serial Bus |
Serial Port | Shader Tools | SpatialAudio | SQL |
StateMachine | SVG | TextToSpeech | UI Tools |
WebChannel | WebEngine | WebSockets | WebView |
XML | Charts | CoAP | Data Visualization |
Lottie Animation | MQTT | Network Authorization | Quick 3D |
Quick 3D Physics | Quick Timeline | Virtual Keyboard | Wayland Compositor |
Some modules could be incomplete, please see wiki.qt.io/Qt_for_Python_Missing_Bindings for more information.
QML only modules, no C++ classes to expose to Python
HTTP Server | Protobuf | Graphs | GRPC | Location |
Won't do due to Python equivalent modules out there
Qt Automotive Suite | Qt M2M Protocols (1) | Qt for Device Creation (2) | Qt for MCU (2) |
(1) KNX is not included, Only MQTT, CoAp, and OpcUA.
(2) Currently in progress to include Qt for Python in Yocto images
(3) The main Python interpreter doesn't have official support on Microcontrollers. Micro/Circuit Python are subsets of Python, and we don't support them.
Windows | Linux |
macOS | Android (1) |
iOS (2) | WebAssembly (3) |
Embedded (4) |
pyside6-android-deploy
aarch64
wheels available on PyPi (>= 6.6).
Cross compilation in RaspberryPi OS and Poky linux is possible.Shiboken
import shiboken6
isValid(obj)
getCppPointer(obj)
isOwnedByPython(obj)
VoidPtr
class$ ./shiboken6 ...
# Common Qt structure
# - Using setter/getter
# - No writable properties
table = QTableWidget()
table.setColumnCount(2)
button = QPushButton("Add")
button.setEnabled(False)
layout = QVBoxLayout()
layout.addWidget(table)
layout.addWidget(button)
from __feature__ import (
snake_case, true_property
)
table = QTableWidget()
table.column_count = 2
button = QPushButton("Add")
button.enabled = False
layout = QVBoxLayout()
layout.add_widget(table)
layout.add_widget(button)
asyncio
supportQt tools
(1/2)PySide6
package
Qt tools
(2/2)PySide6
package
tools
(1/2)PySide6
package
tools
(2/2)PySide6
package
% pyside6-project -h
usage: project.py [-h] [--quiet] [--dry-run] [--force] [--qml-module]
{build,run,clean,qmllint,deploy,new-quick,new-ui,new-widget} [file]
Builds a '.pyproject' file
Builds Qt Designer forms, resource files and QML type files
Deploys the application by creating an executable for the corresponding platform
For each entry in a '.pyproject' file:
- .pyproject: Recurse to handle subproject
- .qrc : Runs the resource compiler to create a file rc_.py
- .ui : Runs the user interface compiler to create a file ui_.py
For a Python file declaring a QML module, a directory matching the URI is
created and populated with .qmltypes and qmldir files for use by code analysis
tools. Currently, only one QML module consisting of several classes can be
handled per project file.
positional arguments:
{build,run,clean,qmllint,deploy,new-quick,new-ui,new-widget}
build Builds the project
run Builds the project and runs the first file")
clean Cleans the build artifacts")
qmllint Runs the qmllint tool
deploy Deploys the application
new-ui Creates a new QtWidgets project with a Qt Designer-based main window
new-widget Creates a new QtWidgets project with a main window
new-quick Creates a new QtQuick project
file Project file
options:
-h, --help show this help message and exit
--quiet, -q Quiet
--dry-run, -n Only print commands
--force, -f Force rebuild
--qml-module, -Q Perform check for QML module
Easy graphical way to generate Python bindings from a C++ project.
Overview video
Generating Python bindings
from a C++ library.
CMakeLists.txt
icecream.cpp
icecream.h
truck.cpp
truck.h
bindings.h
(right top)bindings.xml
(right bottom)β Check the samplebinding example
#ifndef BINDINGS_H
#define BINDINGS_H
#include "icecream.h"
#include "truck.h"
#endif // BINDINGS_H
Simple typesystem
Python usage
from wiggly import WigglyWidget as WigglyWidgetCPP
from wigglywidget import WigglyWidget as WigglyWidgetPY
# ...
wiggly_widget_py = WigglyWidgetPY(self)
wiggly_widget_cpp = WigglyWidgetCPP(self)
# ...
layout.addWidget(wiggly_widget_py)
layout.addWidget(wiggly_widget_cpp)
β Check the widgetbinding example
Embedding Python into a Qt/C++ application
The Text editor interprets Python code to access the Qt/C++ application to modify it.
β Check the scriptableapplication example
For more details, refer to our blog posts
qt.io/blog/tag/qt-for-python
More platforms at wiki.qt.io/Qt_for_Python#Community
Dr. CristiΓ‘n Maureira-Fredes
Senior R&D Manager @ TQtC
Qt Group 2023 CristiΓ‘n Maureira-Fqt-mandarines | @cmaureir