I'm an avid pythonista looking to build my first serious GUI desktop application and it seems Qt is the best option for that, so I've started learning it, and I've found there seem to be three options for how you can build your interface:
Now I'm trying to figure out if there are differences in the capabilities of these three approaches. Do I have equal amounts of control with all three? What are the pros and cons?
Moreover, how much control do I have anyway? Can I customize the UI to a fine degree, like the Spotify interface where nearly everything is a unique custom widget? Or am I stuck with more or less generic out of the box appearances?
I generally use Qt Designer to produce UIs. A fair number of options are available and it gives you a rough sense of what your UI will look like.
However, rather than compile the .ui file into a .py file (which you can subclass) I prefer to dynamically load the ui at runtime using either PyQt4.uic
or PySide.QtUiTools
. Using these, you can call a function, passing it the path to the ui file, and it will return an object for your top level widget/window (for the sake of the next example, we'll say this is placed in my_ui
). This object has attributes for all other ui elements which you can access by my_ui.my_object_name
where my_object_name
is the name you gave the ui element in Qt Designer.
Using this approach means you:
Qt Designer also has the ability to specify widget promotions, so you can insert a basic QLabel
(for example) into your ui, but when you load it, it can be automatically promoted to a subclass of QLabel
which you have made and specified. So you can design the rough shape of your UI in Qt Designer, but easily promote most of the components to custom widgets at run time.
Because of the differing interfaces to the .ui file loader in PySide and PyQt, I wrapped them up as part of a library I maintain (qtutils) so that they have a common interface for loading ui files at runtime and specifying widget promotions.
I also don't have any experience with QML, but based on what I've heard, it's not as powerful as using QWidgets yet. However I think that the people who are writing/developing the Qt library are pushing QML as the way of the future.
My recommendation would thus be to use Qt Designer over pure code, but it would be worth checking out QML in case it does enough for what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With