[PyQt] Doubt

Maurizio Berti maurizio.berti at gmail.com
Wed Oct 2 03:01:34 BST 2019


As the "law of the instrument" says, «if the only tool you have is a
hammer, [you] treat everything as if it were a nail».

There is no perfect tool for everything (nor everybody).
I use to create simpler interfaces directly in code, but for more complex
situations I prefer Designer, as it allows to fix or change the layout
very easily.

In my opinion, the real problem with Designer is that most people (usually
those who are new to Qt or python) don't realize that its output should be
left as it is, especially the pyuic generated files; what happens there
instead is that those people believe that they should write their programs
within those py files. I remember doing the same myself when I began
exploring PyQt.
Being automatically generated, those files contain lots of code that in
most cases is almost useless, particularly to those inexperienced users;
it's what happens with any WYSIWYG editor.

When dealing with mid to advanced GUIs (multi-level nested layouts or
stacked widgets), the common (not absolute!) suggestion is to use Designer,
as it *is* a time saver: it allows to easily see if the interface _works_
from an UX point of view while drawing it, and eventually change the whole
layout in a matter of seconds - something that would take minutes (if not
hours) if the interface is coded.
Most importantly, when you can use a graphical editor for a GUI, you can
really focus *only* on creating the interface, without thinking about good
object names (which can be done once the layout is finished), code
consistency and, obviously, syntax.

One of my programs has a window that contains more than 200 widgets with up
to 6 levels of nested layouts (it's a synthesizer editor, and almost all
controls *have* to be on a single window).
Using Designer I was able to create the basic skeleton in less than 10
minutes, with less than an hour of fine-tuning and object naming/property
setting.
In the earlier version I couldn't use Designer because most widgets
couldn't be just "promoted" (I use custom widget plugins now), coding the
whole interface literally took me at least a dozen hours: dealing with that
amount of layouts and widgets requires careful organization, and it's not
easy to fix or change things with more than 400 lines of layout "code
flow"; most of the time is taken by continuously switching between coding
and running to see if the result worked, both aesthetically and from an UX
perspective (or if it worked at all ;-) ), and eventually go back to the
code, remember the object name you need to fix or change, find it and
finally edit hoping that you're not breaking something.
And if I decide to rethink the whole layout, now it would just be a matter
of 5-10 minutes of drag'n'drop from the existing interface to a new one.

In conclusion.

For basic and simple interfaces, coding is usually simpler and better (no
need to import a 2k file with useless data for a dialog with 3 buttons and
a label).
If you have a more complex GUI, Designer is your friend, especially if you
don't have a specific design in mind yet.
If you can, directly use the ui files (use PyQt5.uic.loadUi to load them,
careful with file paths though): sometimes it happens that you update the
ui but forget to generate the py file).
If you have to use pyuic files, just import them, never touch them, and
ignore their contents (if not for learning purposes).

Maurizio

Il giorno mer 2 ott 2019 alle ore 01:29 michael h <michaelkenth at gmail.com>
ha scritto:

>
>> Anyways, just to be direct, I use Designer and it doesn't seem to have
>> ruined my programs.
>>
>>
> Going to agree with Kyle on this one.
>
> Designer has it's place. I'd rather be working on features rather than
> coding dialogs and other simple windows by hand.
> The ability to do it all by hand is a required skill in my opinion but
> used correctly designer is a time saver.
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20191002/575e0387/attachment-0001.html>


More information about the PyQt mailing list