Qt for Python Getting Started — Qt for Python (original) (raw)

This page is focused on building Qt for Python from source, if you just want to install PySide2 with pip you need to run:

for more details, refer to our Quick Start guide. Additionally, you can check the FAQ related to the project.

General Requirements

Guides per platform

You can refer to the following pages for platform specific instructions:

A normal building command will look like this:

python setup.py install --qmake=/path/to/qmake
--ignore-git
--debug
--build-tests
--parallel=8
--make-spec=ninja
--verbose-build
--module-subset=Core,Gui,Widgets

Which will build and install the project with debug symbols, including the tests, using ninja (instead of make), and considering only the module subset of QtCore, QtGUI and QtWidgets.

Other important options to consider are:

Testing the installation

Once the installation finishes, you will be able to execute any of our examples:

python examples/widgets/widgets/tetrix.py

Running Tests

Using the --build-tests option will enable us to run all the auto tests inside the project:

python testrunner.py test > testlog.txt

Note

On Windows, don’t forget to have qmake in your path (set PATH=E:\Path\to\Qt\5.15\msvc2017_64\bin;%PATH%)

You can also run a specific test (for example qpainter_test) by running:

ctest -R qpainter_test --verbose

Building the documentation

Starting from 5.15, there are two options to build the documentation:

1. Building rst-only documentation (no API)

The process of parsing Qt headers to generate the PySide API documentation can take several minutes, this means that modifying a specific section of the rst files we currently have, might become a hard task.

For this, you can install sphinx on a virtual environment, and execute the following command:

python setup.py build_rst_docs

which will generate a html/ directory with the following structure:

html └── pyside2 ├── index.html ├── ... └── shiboken2 ├── index.html └── ...

so you can open the main page html/pyside2/index.html on your browser to check the generated files.

This is useful when updating the general sections of the documentation, adding tutorials, modifying the build instructions, and more.

2. Building the documentation (rst + API)

The documentation is being generated using qdoc to get the API information, and also sphinxfor the local Python related notes.

The system required libxml2 and libxslt, also on the Python environment, sphinx andgraphviz need to be installed before running the installation process:

pip install graphviz sphinx

After installing graphviz, the dot command needs to be in PATH, otherwise, the process will fail. Installing graphviz system-wide is also an option.

Since the process rely on a Qt installation, you need to specify where the qtbase directory you will use with your qmake is located:

export QT_SRC_DIR=/path/to/qtbase

Once the build process finishes, you can go to the generated *_build/*_release/pyside2directory, and run:

Note

The apidoc make target builds offline documenation in QCH (Qt Creator Help) format by default. You can switch to building for the online use with the --doc-build-onlineconfigure option.

Finally, you will get a html directory containing all the generated documentation. The offline help files, PySide.qch and Shiboken.qch, can be moved to any directory of your choice. You can find Shiboken.qch in the build directory, *_build\*_release\shiboken2\doc\html.

Viewing offline documentation

The offline documentation (QCH) can be viewed using the Qt Creator IDE or Qt Assistant, which is a standalone application for viewing QCH files.

To view the QCH using Qt Creator, following the instructions outlined inUsing Qt Creator Help Mode. If you chose to use Qt Assistant instead, use the following command to register the QCH file before launching Qt Assistant:

assistant -register PySide.qch

Note

Qt Assistant renders the QCH content using the QTextBrowser backend, which supports a subset of the CSS styles, However, Qt Creator offers an alternative litehtml-based backend, which offers better browsing experience. At the moment, this is not the default backend, so you have to select the litehtml backend explicitly under the General tab in Qt Creator >> Tools >> Options >> Help.

Using the internal tools

A set of tools can be found under the tools/ directory inside the pyside-setup repository.

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.