For internal and external distribution
(Slide updated on 14.02.2023)
pyside6-uic, pyside6-rcc,
pyside6-designer
etc.shiboken_generator
is GPLv3*.so, *.dll, *.dylib
)QtOpcUa, QtMqtt, QtCoAp
)(*) Work is being done to include it.
.whl files
)
βͺοΈPySide6
βββ Qt modules β
βββ pyside6-designer β
βββ pyside6-rcc β
βββ pyside6-uic β
βββ ...tools β
βͺοΈShiboken6 (module)
βββ shiboken6 β
βͺοΈShiboken6_Generator (exe)
βββ shiboken6 β
shiboken_generator
The main issue for not having it public
is the dependency with libclang
.
pip install \
--index-url=http://download.qt.io/official_releases/QtForPython/ \
--trusted-host download.qt.io \
shiboken6 pyside6 shiboken6_generator
But one needs to:
python setup.py install
# there are many other options!
doc.qt.io/qtforpython/gettingstarted.html
pip install shiboken6-xxxx.whl pyside6-xxxx.whl
(xxxx contains information about architecture, OS and the PySide, Qt, and Python versions)
βͺοΈ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 5.15
(For Qt6, following available modules)
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 |
OpenGL | Positioning | Print Support | |
Quick Widgets | Remote Objects | SCXML | Sensors |
Serial Bus | Serial Port | SpatialAudio | SQL |
StateMachine | SVG | TextToSpeech | UI Tools |
WebChannel | WebEngine | WebSockets | WebView |
XML | Charts | Data Visualization | Network Authorization |
Quick 3D | Quick Timeline | Shader Tools | Virtual Keyboard |
Wayland Compositor | HTTP Server | Quick 3D Physics |
Some modules could be incomplete, please see wiki.qt.io/Qt_for_Python_Missing_Bindings for more information.
Qt Automotive Suite | Qt M2M Protocols (1) | Qt for Device Creation | Qt for MCU (2) |
(1) KNX is not included, Only MQTT, CoAp, and OpcUA.
(2) Python 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) |
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)
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 vision blog post
qt.io/blog/2019/08/19/technical-vision-qt-python
More platforms at wiki.qt.io/Qt_for_Python#Community
Dr. CristiΓ‘n Maureira-Fredes
R&D Manager @ TQtC
The Qt Company 2023 | @cmaureir