Introduction

The Qt for Python project provides the tooling to bind C++ and Qt to Python, and a complete Python API to Qt. This means that everything that you can do with Qt and C++, you can also do with Qt and Python. This ranges from headless services to widget based user interfaces. In this chapter, we will focus on how to integrate QML and Python.

Currently, Qt for Python is available for all desktop platforms, but not for mobile. Depending on which platform you use, the setup of Python is slightly different, but as soon as you have a PythonIntroduction - 图1 (opens new window) and PyPAIntroduction - 图2 (opens new window) environment setup, you can install Qt for Python using pip. This is discussed in more detail further down.

As the Qt for Python project provides an entirely new language binding for Qt, it also comes with a new set of documentation. The following resources are good to know about when exploring this module.

The Qt for Python bindings are generated using the Shiboken tool. At times, it might be of interest to read about it as well to understand what is going on. The preferred point for finding information about Shiboken is the reference documentationIntroduction - 图6 (opens new window). If you want to mix your own C++ code with Python and QML, Shiboken is the tool that you need.

TIP

Through-out this chapter we will use Python 3.7.