diff options
author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2024-03-15 13:27:18 +0100 |
---|---|---|
committer | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2024-03-19 15:26:26 +0100 |
commit | 0babbf03eee5a95fdf26c92c9de699af4c8616d3 (patch) | |
tree | 4139e8837b473111522bb81ae239f681042ba909 | |
parent | afbd87359bc5e959bac28cc0318794aa2231a91c (diff) |
doc: add page for pyside6-uic
Include a short summary of the main usage, some caveats
and reference to the tutorial.
Change-Id: I0dfdeb914d5e590f5992a44d54eddcb4ccec970d
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r-- | sources/pyside6/doc/tools/pyside-uic.rst | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sources/pyside6/doc/tools/pyside-uic.rst b/sources/pyside6/doc/tools/pyside-uic.rst new file mode 100644 index 000000000..3fe5d9ccc --- /dev/null +++ b/sources/pyside6/doc/tools/pyside-uic.rst @@ -0,0 +1,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 + |