Since a couple years passed by and some things were fixed: I guess the official answer would now be:
Use uic.exe
! But how?
So although the official docs still lack any info about it you can now compile .ui
files to Python directly with this executable shipped with the PySide2 package you get via pip install PySide2
. This is how you would write it:
uic.exe -g python your_design.ui -o your_design_ui.py
Where your_design.ui
is the Qt Designer file and your_design_ui.py
the target Python file to generate. Voilà!
Btw: here is the help from uic -?
C:\Python38\Lib\site-packages\PySide2>uic.exe -h
Usage: uic.exe [options] [uifile]
Qt User Interface Compiler version 5.15.0
Options:
-?, -h, --help Displays help on commandline options.
--help-all Displays help including Qt specific options.
-v, --version Displays version information.
-d, --dependencies Display the dependencies.
-o, --output <file> Place the output into <file>
-a, --no-autoconnection Do not generate a call to
QObject::connectSlotsByName().
-p, --no-protection Disable header protection.
-n, --no-implicit-includes Disable generation of #include-directives.
-s, --no-stringliteral Deprecated. The use of this option won't take
any effect.
--postfix <postfix> Postfix to add to all generated classnames.
--tr, --translate <function> Use <function> for i18n.
--include <include-file> Add #include <include-file> to <file>.
-g, --generator <python|cpp> Select generator.
--idbased Use id based function for i18n
--from-imports Python: generate imports relative to '.'
Arguments:
[uifile] Input file (*.ui), otherwise stdin.