pyside6-uic

Note

This tool is automatically called by pyside6-project so you don’t need to call it manually. Qt Creator will take care of this step as well while executing a project.

pyside6-uic is a command line tool for converting .ui files into .py files, with the objective of using application designs as Python classes.

The tool is a wrapper around the uic tool, which was originally designed to generate C++ code, but it also has Python support.

Even though the equivalent of pyside6-uic is running uic -g python we strongly recommend you to rely on pyside6-uic in order to avoid mismatches between versions for the generated code.

Usage

Once you have designed your application with pyside6-designer, you can transform your .ui file with the following command:

pyside6-uic your_file.ui -o ui_your_file.py

It is important to use the -o option to generate the Python file with the conversion, otherwise you will receive all the output as stdout in your terminal.

The structure of the generated Python file will be similar in all cases, and you will get one class called Ui_TheNameOfYourDesign(object) that is in charge of positioning all the elements like your design.

To use this Python file, you should follow our tutorial in using_ui_files, but in summary, it is mainly importing the class from the generated file and setting it up in your code:

self.ui = Ui_TheNameOfYourDesign()
self.ui.setupUi(self)

For additional options, you can use pyside-uic -h in order to get more information related to relative imports, absolute imports, using resources, translations, etc.

Note

Remember that you need to have a class corresponding to the base form you selected in pyside6-designer, a QWidget, or QDialog, or QMainWindow, etc, in order for setupUi to work. Check using_ui_files for more information.

Warning

Do not modify the content of the generated Python file from your .ui file, otherwise everything will be lost when you re-generate it.