Add a new example or port one#
Adding examples is a good exercise for people wanting to become familiar with the modules and its functionality.
You can either design an example from scratch or inspired in another application, or simply you can port an existing Qt example that does not have a Python counterpart.
For both cases, we recommend you to use tools like flake8 (or ruff) to detect issues with your code. Keep in mind we do allow 100 columns for line length. Additionally, please use isort to keep the imports ordered and consistent with other examples.
$ flake8 --ignore=E266 your_file.py $ isort your_file.py
Add a new example#
Check if the topic your example covers is not in an existing example already.
Create a new directory inside the
examples/<module>you think is more relevant.
Inside, place the code of the example, and also a
.pyprojectfile listing the files the example needs.
If you want the example to be automatically displayed on the example gallery, include a
docdirectory that contains a
rstfile and a screenshot. Check other examples for formatting questions.
When writing the
rstfile, you can include code snippets using the
literalincludedirective specifying the relative path as listed in the
.pyprojectfile. The example_gallery tool will expand this (see the pointconfiguration example).
For the code displayed in the tabs, you can create
rstincfiles in the
docdirectory containing some description explaining them (see the samplebinding example).
Port a Qt example#
Quickly check the C++ example, fix outdated code.
Port the sources using
Note that our examples need to have unique names due to the doc build.
Verify that all slots are decorated using
.pyprojectfile (verify later on that docs build).
docdirectory and descriptive
.rstfile, and a screenshot if suitable (use
optipngto reduce file size).
"""Port of the ... example from Qt 6"""doc string.
Try to port variable and function names to snake case convention.
Remove C++ documentation from
Example screenshots in
.png should be optimized by
optipng -o 7 -strip all. Alternatively, the
.webp format can be used.