aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/tools/pyside-uic.rst
blob: ba4e36b4e007f0f896460d953162fe7f6e90404b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.. _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:`using_ui_files`, 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:`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.

.. _`uic`: https://doc.qt.io/qt-6/uic.html