Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Designer, UIC, and PyQt


  • Banned

    [EDIT: Forked from https://forum.qt.io/topic/108465/absolute-beginner --JKSH]

    Eeghads do yourself a major favor and stop using the Designer to make python code it was not designed for that and the translation program creates extremely horrible python/pyqt code. Further actually learning to create those GUIs without using the Designer is very easy and creating them once you know how to do it properly is just as fast or faster than using the Designer and the ultimate benefit is you have code that (1) You understand how it works and why (2) You have code that you can tweak and manipulate later on when go to add in other functionality. Every person that I have taught thus far has come to the solid understanding of just how bad the Designer is some a bit slower than others -- aka some had to experience more of the pains that occur with using that code base before fully understanding why they did not want to use it



  • @Denni-0 said in Absolute beginner:

    Eeghads

    wow, what a way of entering a room kicking doors... Completely unnecesary it seems here

    do yourself a major favor and stop using the Designer to make python code it was not designed for that and the translation program creates extremely horrible python/pyqt code.

    Could it be possible you show examples of both code snippets to really assert the differences?

    I've used Qt Designer for several years, to create applications with C++ and now that I'm slowly moving to Python as well, I find it completely natural to design the UI in Qt Designer (a thing I've done for so long so far) and then resorting on some tool to convert the .ui file (XML representation) into actual code, in this case PySide2 source code.

    how bad the Designer is some a bit slower than others

    Indeed, technically speaking "Designer" couldn't be bad since it doesn't generate any code at all. The same GUI design (.ui) file could be later translated to C++ or Python.

    If you really now that such translation to Python code is really bad, I'd ask you please to be more verbose since I'm interested in not to step into such trap. Again, designing a GUI visually is very good and straightforward so taking advantage of Qt Designer is a really interesting, but if you could show us that should be avoided, I honestly do consider it.


  • Banned

    @Pablo-J-Rogina okay should I have smiled and winked with the Eeghads ;) note the Eeghads is because it is perhaps the most horrible thing that has been propagated to newbies causing them a world of pain and hurt and it gets propagated by lazy python-pyqt coders and of course the unknowing newbies

    As for code examples -- I think I have done that a few times already on this site -- if they have a means for you to check out my posts then go peruse them for that information

    Now I do not know what the code looks like for C++ -- perhaps it just uses the native XML that the designer creates it in -- but the translator takes that XML code and converts it into extremely ugly looking horrible to work with python/pyqt code. So sure if you want to work with that native object as it was meant to be by all means do so -- but most python/pyqt coders have an easier method called coding it like pyqt was meant to be coded rather than using the designer to make HTML code and then worse converting it into python-pyqt code

    To your last question -- their are numerous issues with the converted UI some of that is unnecessary code, some of it is improper methodology due to perhaps not fully understanding the Designer which would take actually more work than learning to use native pyqt to do it from scratch. The short of it is this is -- it adds a major level of unnecessary complexity and creating the GUI from scratch properly using native pyqt is just as simple as doing it via the Designer -- once you understand the basics of coding in pyqt that is (which again is not that complex really) -- further the cleaner code base that you now have and fully understand how it works (its not a mysterious untouchable black-box anymore) is very easy to tweak and add to



  • @Denni-0 said in Absolute beginner:

    uses the native HTML that the designer creates it in -- but the translator takes that HTML code and converts it into extremely ugly looking horrible to work with python/pyqt code.

    Have you ever edited an .ui file created by Qt Designer?

    It's not HTML, it's just XML to describe the design of a GUI object (a mainwindow, dialog, etc.). with its components (i.e. widgets), placement (i.e. layouts). See this fragment of a .ui file for instance, voilá NO HTML at all:

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>AboutDialog</class>
     <widget class="QDialog" name="AboutDialog">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>256</width>
        <height>349</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>AboutDialog</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
        <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <spacer name="horizontalSpacer_3">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
         <item>
          <widget class="QLabel" name="lblText">
           <property name="sizePolicy">
            <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
    ...
    

    So maybe you have a misconception about what Qt Designer does (if we after all are talking about the same tool). See some other

    if you are planning to make a UI that has to be ported to multiple destinations then use the native Designer HTML and do not convert it

    Well, again it looks like you don't know the purpose of Qt Designer. The idea is that using this WYSIWYG tool, you create an "ultra-portable" .ui file that then it's just translated into some coding language being it C++ or Python that can actually run in several different platforms.

    creating the GUI from scratch properly using native pyqt is just as simple as doing it via the Designer

    As mentioned earlier, I'm just starting to code in Python so for me the situation is quite the opposite as you described!! Without knowing very little Python/PySide2 I'm able to design and have it running some decent GUIs, the same way I've doing for long years with C++. For me it's a win-win situation


  • Banned

    @Pablo-J-Rogina yes I have -- I did look at the actual designer created code -- and my bad forgot it was XML rather than HTML (adjusted my previous post accordingly) but then the two do look rather similar and in many ways act very much a like -- and unless I am doing a web-page which is rare I do not use either -- use JSON object instead or make one of my own depending on the language I am coding in

    Okay then yes I misunderstood its purpose because as I thought the translation was something secondary to what the UI was designed for (as that made more sense to me) mainly because it is horrible code to work with and does not follow good python-pyqt coding methodologies -- so with explanation (and assuming I am now understanding it better once more) it truly is a next to worthless application when it comes to python-pyqt for all the reasons I have stated to date

    Okay but I am going to guarantee that you will (sooner or later) run into major issues when it comes to using the python-pyqt translated code -- most folks do -- either that or they take sometimes extreme and always unnecessary measure to get that code to work -- which uses more time than had they done it they way it ought to have been done in the first place

    black-box code is dangerous code always -- and should only be used when absolutely necessary -- like calling an outside API -- and even then good companies analyze that closely prior to committing to using a black-box bit of code



  • @Denni-0

    called coding it like pyqt was meant to be coded

    PyQt was not meant to be coded in any particular fashion. It's just a language binding to Qt libraries.

    creating the GUI from scratch properly using native pyqt is just as simple as doing it via the Designer

    No, it is not, certainly not for "absolute beginners". I have had to code all my PyQt stuff dynamically, and it is a lot more laborious, error-prone and requires greater initial knowledge than using a UI to design visually. As in other IDEs. So clearly opinions differ.



  • @Denni-0 said in Absolute beginner:

    because it is horrible code to work with and does not follow good python-pyqt coding methodologies

    Show me the code! :-)
    Seriously, this is an assertion with no sustain, at least for a beginner like me. It sounds like a bluff...

    Could it be possible that you show code snippets to compare for let's say "a label and a button attached to a horizontal layout with some spacers placed into a dialog", both from the "evil" generated code and your hand-coded approach? If not, for me your saying will continue as an opinion rather than a fact.

    In addition, I realized that all your references are to PyQt. Please remember that there's also another player in the field since a year ago or so: PySide2. So there's another .ui -> Python translation tool.

    Have you checked what type of code that the translation generates?

    Could we say it's acceptable to your standards?

    black-box code is dangerous code always

    Another heavy assertion here...

    I tend to think about the .ui design into code translation slightly different, in the sense that given a bunch of developers that use Designer to layout certain GUIs, all of them can be sure that the code that will actually be using will be the same because all the components were written by the same tool.
    And if some developer leaves the team it doesn't matter later.


  • Banned

    @Pablo-J-Rogina do you use the Designer -- if yes then create that code you want converted into standard Python-PyQt and I will show you the night and day difference. Otherwise there are numerous examples on this forum as well as on the internet in general of the garbage "black-box" code that the Designer creates along with the headaches that come with that "black-box" code

    Next again I believe I have even posted on this forum examples of converting that garbage code into good quality Python-PyQt code more than once and I have nothing that I need to prove to you. If you cannot find that information on your own then you need to learn how to use google search a lot better as that is how I found it

    As for PySide2 vs PyQt -- the only real difference between these two is the license LGPL vs GPL -- and that PySide2 is significantly lagging behind PyQt at being fully up to date

    The heavy assertion of "black-box code" being dangerous is a known fact by nearly every company I have ever worked with that had gotten burned by "black-box code" and frankly that is quite a few companies so it is not like its an unknown factor

    As for your thinking -- I would say if the company had basic coding standards implemented so that code that is created has the same basic look and feel from programmer to programmer they would have that guarantee but completely across the entire code base -- and this concept of coding standards is something many coding houses have come to understand and have implemented for the very same reasons that you state -- but none of them would allow for unnecessary black-box code and what the Designer is used to create is almost always completely unnecessary since coding it straight forward as it should have been takes about the same amount of time and what you end up with is something that is fully understood and easily tweaked and/or augmented later on



  • @Denni-0 said in Absolute beginner:

    As for PySide2 vs PyQt -- the only real difference between these two is the license LGPL vs GPL

    No, it's not. The tools used by them are different so you can expect different outcomes



  • @Denni-0 said in Absolute beginner:

    code that the Designer creates

    Again, Qt Designer doesn't create ANY code.

    You keep on this notion again and again, which differs from reality. The code is created by tools taking Designer output (.ui files) as input and creating Python (or C++) code (depending on the tool).


  • Banned

    @Pablo-J-Rogina okay you seem to be arguing just to be arguing and that is called being a Troll

    PySide2 and PyQt5 are both based on QT5 as the underlying code base -- so they are in essentially the exact same thing all they are doing is converting the QT5 C++ based code into Python Qt code -- so again essentially the same thing since all they are doing is converting the same base code -- this discussion on this is done

    Qt Designer creates an XML code base that is based on the Design you create using its WYSIWYG this then is translated/converted into python code to be used with python programs -- so it DEFINITELY creates code -- this discussion on this is done

    Please stop your nonsensical trolling you have been warned



  • @Denni-0 said in Absolute beginner:

    Qt Designer creates and XML code base based on the Design you create using its WYSIWYG this then the translated/converted into python code to be used with python programs -- so it DEFINITELY creates code -- this discussion on this is done

    LOL, except that it, Qt Designer, does not create code. Here's from the Riverbank (PyQt) docs:

    Qt Designer is the Qt tool for designing and building graphical user interfaces.
    Qt Designer uses XML .ui files to store designs and does not generate any code itself.

    That "Qt designer [...] does not generate any code itself" is pretty plain. It doesn't generate the C++ code either. But the discussion on this is done. You're just wrong, and rude.

    P.S.
    Politely. The generation of the Python code from the XML files is done by an external tool, supplied by Riverbank. Just as @Pablo-J-Rogina said. Interestingly, you can replace that tool with your own. If you do not like the python code generated by Riverbank, if you can express how you do your "Hand coding" equivalent with better code as an algorithm then you might enjoy writing your own translator to Python code :)


  • Banned

    @JonB that is basically arguing semantics versus content the whole purpose of the Designer is to give a programmer a WYSIWYG method to create code from -- and technically it DOES CREATE that XML.ui file and XML is Extensible Markup Language and thus by definition a programming language and thus by definition when the Designer creates this file it is creating code regardless of what anyone says about it to the contrary

    That being said again its whole purpose is to allow you to then use one of their other Designer associated tools to convert that Extensible Markup (Programming) Language into the specific code language you are wanting to use. So its whole intent and purpose is to create code to render your GUI. Note these Designer associated tools are completely useless without the XML code that was created by the Designer making them just extensions of the Designer and not some autonomous code base

    Sure you can argue the semantics but when it is all said and done you will have a code base for your GUI that came from the Designer and its associated tools. Thus by content definition it creates code

    As for writing my own converter I do not see the point -- coders are lazy enough as it is ;) and frankly when writing one of these you have to constantly keep it updated -- so perhaps after I retire and have oodles of time on my hands I might consider doing that but until then all I can say is stop being a lazy coder and get your hands dirty with the real code and find out just how easy it is to do

    As a final note I run a Discord Python-Pyqt message server where I help folks learn how to do this and more so it is not like I am not actively pursuing a more quality answer



  • @Denni-0 said in Qt Designer, UIC, and PyQt:

    okay you seem to be arguing just to be arguing

    No, you're not right here. We are having different opinions, and trying to figure out our options regarding some technical topics.

    that is called being a Troll

    You are behaving kinda rude again. I still remember your post regarding "eggheads"...

    And given the number of posts made so far, in addition to my reputation in the forum I know for sure it's very clear I'm not a troll.

    Putting politeness aside, let's get back into the poor code the XML into Python translation tools issue.

    Here you have a simple two button dialog (from one of the options Qt Creator offers) + a label saved as dialog.ui and then converted to Python by pyside2-uic (5.13.2).
    Honestly, could you please show us what problem(s) such code is suffering?

    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'dialog.ui',
    # licensing of 'dialog.ui' applies.
    #
    # Created: Fri Nov  8 09:38:54 2019
    #      by: pyside2-uic  running on PySide2 5.13.2
    #
    # WARNING! All changes made in this file will be lost!
    
    from PySide2 import QtCore, QtGui, QtWidgets
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(400, 300)
            self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
            self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
            self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
            self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
            self.buttonBox.setObjectName("buttonBox")
            self.label = QtWidgets.QLabel(Dialog)
            self.label.setGeometry(QtCore.QRect(150, 110, 85, 22))
            self.label.setObjectName("label")
    
            self.retranslateUi(Dialog)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
            QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(QtWidgets.QApplication.translate("Dialog", "Dialog", None, -1))
            self.label.setText(QtWidgets.QApplication.translate("Dialog", "TextLabel", None, -1))
    

  • Banned

    Okay @Pablo-J-Rogina you need to supply the code necessary to instantiate and display this UI file since if I remember correctly to do it is rather convoluted -- which is to say to display the above I cannot simply just -- self.MyWin = MyDialog() and then show that. I make this requirement because before I post my working example I want to test that yours actually works



  • @Denni-0 said in Qt Designer, UIC, and PyQt:

    you need to supply the code necessary to instantiate and display this UI file

    really?

    I'm not sure if that's necessary for you to comment on what's wrong with that snippet of code in my previous post.

    Let's say that somebody is sharing that dialog.py with you to use a common component within the development team, in order for your application to have the same dialog as other existing applications already in use.

    So assume that you don't even know it was really created by a tool, not hand coded by a programmer... the big question still is:
    what is wrong with that code?


  • Banned

    Well first and fore most what is wrong with that code is that one cannot easily just determine whether or not it works properly since normalish techniques to turn it from a class into an actual usable object are not viable -- as it is NOT a viable object straight out of the box -- typically you have to do some minor back flips within your code to just get that piece of junk into a viably usable state as you cannot just instantiate it and use it as is.

    Further if someone on my development team gave me that piece of junk I would go the manager because that is not a self contained object that can be instantiated and used like all other self contained autonomous objects should be as that one requires special coding to implement within another piece of code -- which is just another issue with that garbage. I have had to implement quality standards on development teams before and this garbage is something that would not fly when using quality standards -- for instance how do you functionally test that piece of code.

    So if you truly want to see what else is wrong with that code and have not just been trolling as you have claimed you are not -- provide an MRE of that code and I will post my MRE version of it as well (which is finished, tested and ready for use right out of the box as is). Otherwise I will just view you as the Troll you have definitely appeared to be thus far -- that is my final word on this as well -- no MRE nothing more from me as I do not negotiate with Trolls

    P.S. Considering your code as is will not run in PyQt5 (even after changing the reference from PySide2 to PyQt5) and I am only running PyQt5 you might want to fix the bugs in it so that it is PyQt5 compatible just yet another issue with that code and you



  • @Denni-0 said in Qt Designer, UIC, and PyQt:

    you're just selling snake oil on and on...

    provide an MRE of that code

    Here you have an example to know how to use the class I provided

    that piece of junk I would go the manager because that is not a self contained object

    so given a class you're not able to instantiate an object? Come on.

    P.S. Considering your code as is will not run in PyQt5 (even after changing the reference from PySide2 to PyQt5) and I am only running PyQt5 you might want to fix the bugs in it so that it is PyQt5 compatible just yet another issue with that code and you

    I'm just sticking to PySide2 so it looks that fortunately our roads diverge here.

    So...

    this discussion on this is done

    Yes indeed.


  • Banned

    Yep just as I thought you were out Trolling -- but sorry you are right I am not buying your Snake Oil

    Next I think I told you from get go I have nothing I need to prove to you - as you are completely inconsequential to me.

    No given a proper class I can instantiate the object -- I even figured out the necessary back-flips to get your wanna-be class to display but that means I had to write extra code to just get your code to work -- which makes it not a real class at all -- heck not even a real library since you cannot use its functionality stand alone it takes at least 6 quality lines of code and a whole other class to just get your so called class to work -- again not a TRUE class by any stretch of the imagination

    As stated previously your code base as it is does not run because it has errors due to your using the Designer to create that code from something that by your claim does not create code -- strange how that works aye -- further your code base is far more complex than it needs to be which is why it has these errors when moving it from PySide2 to PyQt5

    As it stands the fact that you cannot (or will not) provide an MRE is just sad so very sad -- the simplest thing in the world to do if you were a real programmer -- heck I even made one for your code that is why I know your code base has bugs in it but I knew you would not step up to the very line you drew because that is the nature of Trolls like yourself -- start off-topic conversations so you can argue about meaningless garbage then balk and run when you are faced with a real challenge

    Again this is your power trip not mine -- to me you are just some meaningless nobody that just got even more meaningless with this wasteful and useless endeavor -- as I stated at the beginning learn to google better -- I have posted numerous examples of why the Designer produces horrible code to folks that had meaning because they truly wanted to know. Further I have a fairly good sized base of students that I help on a fairly regular basis -- and they all got a chuckle out your lame arguments for the Designer -- as they have all gone through the pain of the Designer and then saw the light of not using it


  • Lifetime Qt Champion

    Dear @Denni-0

    How on this freaking earth did you come to the conclusion that
    our valued member @Pablo-J-Rogina is trolling you?

    You come here with a nonprofessional statement about the quality of the code
    that the uic tool generate for the Designer app.

    He then tries to ask you, what you think is wrong with the code
    and you

    • attack him
    • and his code samples/attempt to help
    • does not provide any useful information
      outside of calling the code garbage and impossible to test.

    On top of that - it turns out you might be talking about PyQt5 which is
    a competing vendors product...

    and then you have the nerve to write to him

    • start off-topic conversations so you can argue about meaningless garbage

    Which was how you started this post,
    how you acted here
    and how you ended.

    So if you really wanted to talk about the uic tool for python and how you feel
    the generated code is not good enough, then I suggest you start over in a more constructive way if anything good should come from this.


  • Moderators

    @Denni-0 said in Qt Designer, UIC, and PyQt:

    You cannot (will not) provide an MRE sad so sad -- simplest thing in the world to do -- made one for you it is why I know your code base has bugs but I knew you would not step up to the very line you drew because that is the nature of Trolls like yourself -- start off-topic conversations so you can argue about meaningless garbage

    Personal insults are never justified. Please present your points using technical arguments (for example, "Doing ABC requires 25% fewer lines of code than XYZ" or "I find ABC easier to maintain than XYZ"), not vitriolic rants.

    @Denni-0 said in Qt Designer, UIC, and PyQt:

    Well first and fore most what is wrong with that code is that one cannot easily just determine whether or not it works properly since normalish techniques to turn it from a class into an actual usable object are not viable -- as it is NOT a viable object straight out of the box -- typically you have to do some minor back flips within your code to just get that piece of junk into a viably usable state as you cannot just instantiate it and use it as is.

    Be aware that the output of UIC was never intended to be fully autonomous object. It is intended to be an internal helper class that sets up the physical layout of the actual widget and acts as a container for the widget components, but it does not contain the business logic of the widget. Most importantly, it is not the widget itself.

    I have not used PyQt or Pyside so I cannot comment on how Pythonic (or un-Pythonic) the UIC output is. However, using it in C++:

    • The code I need to write in my real Widget class is reduced because I don't need to write anything to create and lay out the widget components.
    • I never need to read or edit the code generated by UIC. Therefore, it doesn't matter that the code is messy -- all that matters is that the code is correct.
    • It is a good thing that the UIC output is separate from my actual widget code, because that means I can edit the GUI in the WYSIWYG Qt Designer and generate new code via UIC without affecting my business logic -- my custom-written code will still work as before, assuming that I don't rename any of the components.
    • The Qt Creator IDE automatically generates the glue code for me to use the UIC output class (Ui_Widget) in my actual widget class (Widget). All I need to do is insert my business logic into the generated template.

    If the experience in Python is not like this, then I recommend users contact the maintainers (Riverbank for PyQt, Qt Company for Pyside) and explain what needs to be improved. However, "The UIC output cannot be instantiated directly" is not a shortcoming.



  • @Denni-0

    Otherwise I will just view you as the Troll you have definitely appeared to be thus far
    the simplest thing in the world to do if you were a real programmer
    because that is the nature of Trolls like yourself
    to me you are just some meaningless nobody that just got even more meaningless
    as I stated at the beginning learn to google better
    your lame arguments for the Designer

    Denni, it's clear you have different views from some of us here, that's fair enough. You have your opinions of others' views, and others have their opinions of yours. That can result in healthy and polite discussion.

    But, IMHO at least, the phrases quoted above are inappropriate in a forum like this. Especially when you write "to me you are just some meaningless nobody that just got even more meaningless". I don't know if you say that sort of thing at work about your colleagues, but it's really not nice. Why not put your arguments without the personal insults?


Log in to reply