Question about using .ui files from QtDesigner


In many sources it is described how the ui files created with the QtDesigner are converted to a .py file using pyuic (4/5) in order to import this file and to generate a new class using inheritance.

But there is also the following possibility to use the ui file (s) directly:

> from PyQt5 import uic
> class Ui (QMainWindow):
>      """ Main window class of my cool app """
>      def __init __ (self, * args, ** kwds):
>          super (Ui, self) .__ init __ (* args, ** kwds)
>          """ Initialize the UI Class """
>          uic.loadUi ('ui / mainwindow.ui', self)

This seems to me to be a much faster and more convenient way because converting is unnecessary. Only that does not seem to be common. Are there any significant disadvantages to doing this?

Greetings Kai


Auto complete doesn’t work in your IDE if you use ui files. If I recall correctly I also had issues with pyinstaller not knowing to include the ui files but that was a few years ago. I still do the conversion for Auto-completion.


Thanks for the answer. If the missing autocompletion is really the only limitation then I can live with it well.

When using the pyinstaller, you really have to be careful and specify the ui files in the spec file at “datas”.

datas = [('ui/awesomeApp.ui', 'ui/'),('ui/awesomeDialog','ui/')],


The loss of autocomplete mentioned by @cmoman is the only reason I can think of too.

For the conversion I usually I usually create a small bash script to convert all the .ui files in a project in one go. Maybe you could hook something up to auto-convert on file changes?


Thanks for the tip about file specs with pyinstaller


Can you bundle your UI as ui files, rather than as py files doing it like this? Keeps the design/logic distinct which is nice.