2

We can use qt designer to create pyqt or pyside UI.

Ex) exUI.py

MainWindow.setObjectName("MainWindow")
MainWindow.resize(484, 371)
self.centralWidget = QtWidgets.QWidget(MainWindow)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)

Ex) exUI.ui(or XML)

<widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>484</width>
    <height>371</height>
   </rect>
  </property>
  <property name="windowTitle">

When creating a ui using qt designer, a ui file is created as an output.

There are also functions that change the ui to a python file. But I'm curious why you change it to a python file.

A ui file can easily write ui, so why change it back to a python file and make it inconvenient?

Not everyone uses this method, but some do. I wonder if there is a difference in using different file extensions.

Assuming that ui behaves differently when it is a ui file and a python file, I would like to know if PySide and PyQt are both that different.

KimJitae
  • 139
  • 11

2 Answers2

3

TL; DR; Both are generally equivalent forms.


The .ui is just an XML that has the settings (type of widgets, geometry, etc.) to create a widget, that is, Qt developed that format so that the user can design the GUI using the QtDesigner tool quickly and easily.

That .ui is parsed by other methods to create the code that creates the GUI. This parsing can be static (using uic or pyuic) or dynamic (using loadUi, loadUiType, QUiLoader, etc).

The use of one or the other method depends on the developer, and for example if the .ui is used through dynamic methods then the IDEs will hardly help in the autocompletion.

In conclusion, there is no difference since in the end the .ui is converted to code. But there may be a difference in how PyQt and PySide are converted to code since each company can take certain default settings.

One drawback with using .ui is that it obviously takes some time to parse and create dynamic objects, plus you won't benefit from pre-compiling the .py code in most modern versions of python, but in In general, that time cost is minimal.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • If both are of the same form, is the speed the same? I made exe files with pyinstaller, but the execution speed is slow and the capacity is large, so I asked this question while thinking about how to reduce them. When using pyinstaller, which method would you choose between ui file and python file if you are using UI? – KimJitae Jun 28 '21 at 00:48
  • 1
    @김지태 You yourself have the answer: Try both methods and analyze which is more beneficial for you and choose one. For my own taste I don't use the .ui (that is not technical at all) – eyllanesc Jun 28 '21 at 00:53
  • I did what you said and it doesn't seem to make much of a difference in speed. I see one difference, that is, when I create an exe with pyinstaller, if it is a ui file, I need to prepare a separate ui file, but if it is a python file, "UI.py" is not visible. In my opinion, the invisible "UI.py" looks more secure programmatically. What do you think of these differences? – KimJitae Jun 28 '21 at 01:31
  • 1
    @김지태 What do you mean by "security"? security is not the same as visibility. I recommend you take into account if it is important to you since otherwise we will be arguing a lot unnecessarily that in my case I avoid. bye – eyllanesc Jun 28 '21 at 01:31
  • Ah! I'm still learning programming, so I don't know much, so I wanted to hear other people's opinions when I was wrong. I don't want to fight. Thank you for your help. Thank you. Thanks for telling me how to solve the problem. Have a good day !! :) – KimJitae Jun 28 '21 at 01:35
  • 1
    @김지태 SO is not a place of teaching but of Q&A whose consequence may be that you use it as part of your learning but unfortunately / fortunately we limit ourselves to solving problems and we do not want to cover a broader field such as teaching. Please read [ask] and review the [tour] – eyllanesc Jun 28 '21 at 01:39
  • Oh, I didn't know this was a ban on "requests for lists, polls, comments, discussions, etc." My mistake. Sorry. Thanks for letting me know, I'll be careful – KimJitae Jun 28 '21 at 01:48
  • @김지태 the speed issues are likely related to bundling your Python application in an exe. You basically have to unpack a Python virtualenv and all modules (if you use the `--onefile` option for pyinstaller), so the startup is noticeably slow. You can mitigate this to some extent (see for example https://stackoverflow.com/questions/44250280/speeding-up-an-exe-created-with-pyinstaller) TL;DR use `--onedir` instead of `--onefile`, use pyinstaller in venv with no extra packages. – tdpu Mar 22 '22 at 04:32
1

The main reason to create python files for me, is the integration of said files to my IDE (Intellij IDEA).
After the conversion, I can have auto-completion, jump to definition and many other usage benefits..

noEmbryo
  • 2,176
  • 2
  • 10
  • 15