I would like to hear some opinions on hand coding your GUIs as one typically do when using Java or Qt with C++, vs using a gui-designer tool? Examples of GUI designer tools would be MFC GUI-designer, Qt designer, Interface Builder (Apple).
I used to be a fan of hand coding but from recent experience I have switched. The problem I have seen with hand coding is that it is fairly quick and flexible to write the GUIs but once you need to make a change to a GUI written a long time ago it can be very difficult. Finding the right element in big panel can be difficult.
The second problem is that it makes it far too easy to add a lot of logic in the GUI creation and layout code. I have often had to take over maintenance of GUI code which is really hard to reuse because its behavior is mixed with its appearance and mixing layout and behavior often makes the class very large and difficult to understand.
Using a GUI designer tool force a much clearer separation between appearance and logic in my view.
I feel strongly that you should use an interface builder instead of hand-coding a GUI. As in the question mentioned it's a much cleaner separation and once something has to be edited it's much easier.
The Qt Designer got this feature to create a class out of a .ui
file1), but I think that not using this feature is the best way, as this creates just more coded that shouldn't exist at all. The speed issue of creating the window from a .ui
-file is negligible because the window has to be loaded only once.
This is PyQt, but something similar is possible in C++:
class SelectDateDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
uic.loadUi("resources/SelectDate.ui", self)
Essentially this has the same effect as including all your UI-code into the __init__()
method, but the UI is almost completely separated from the code.
1).ui
files are XML files that describe a user interface