.. _pyside6-uic: pyside6-uic =========== .. note:: This tool is automatically called by :ref:`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 :ref:`pyside6-designer`, you can transform your ``.ui`` file with the following command: .. code-block:: bash 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 :ref:`tutorial_uifiles`, but in summary, it is mainly importing the class from the generated file and setting it up in your code: .. code-block:: Python 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 :ref:`pyside6-designer`, a ``QWidget``, or ``QDialog``, or ``QMainWindow``, etc, in order for ``setupUi`` to work. Check :ref:`tutorial_uifiles` 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. .. _`uic`: https://doc.qt.io/qt-6/uic.html