5

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:

  • QML
  • Qt Designer
  • Pure code (python/C++ only)

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?

1

4 Answers 4

6

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:

  • don't have to compile the ui file to a py file
  • Can still access all widgets in your ui using a pythonic interface, allowing you to configure the widgets as if you had created them with pure code

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.

3

I've been working with PyQt for a while (4+ years) and I prefer coding the UI for simple applications; but otherwise, I use Qt Designer. With PyQt, you can convert the .ui file generated by the designer to a .py file, so if something is not completely to your liking, you can always override it in your code (like override QWidgets, etc.).

As for writing applications with beautiful UI... well, Qt does take CSS for styling, though I'm not sure how extensive its support is. QML is the new kid on the block and while I haven't worked on it yet, I looked at some examples and all the applications look gorgeous and fairly simple to write - as you probably know, it has a JavaScript-style syntax, and I believe Spotify was written in JS (though I could be completely wrong).

If you're a Windows developer for example, the way I see "regular" Qt vs QML is kind of like Windows Forms and XAML/Windows Store apps for Windows 8.

In short: yes, you can customize the "look'n'feel" of Qt applications greatly, but I'm not sure how easy that would be compared to e.g. QML.

3

In my expirience, after you've mastered layouts - pure code all the way. No hassle with subclasses, multiple inheritance, additional files in your project. And you can easily create helpers\specialized classes to make building of the GUI realy simple. In fact, I think it's a common way - use Qt Designer to ease the learning curve and then switch to pure code. Just my two cents, YMMV.

1

Well I am not expert on PyQt. But I have fair amount of experience in QWidgets and Qml. I would choose Qml at any time because of its simplicity and ease of coding GUIs. Also you have complete control over the GUI. You can do pretty much anything with QML. The best thing about QML is you can build any app for any screen resolution. Means if you design it for one screen you can make sure that the app runs on any screen without modifyimg qml code. Thanks to its parent child property dependance. Another best thing is once you build for one platform like windows. You can build it for any platform like Linux, android, macOs, iOs with almost no code change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.