Best way to manage UI layout in Qt



  • Hi,
    We are trying to see what are the best ways to manage laying out of various child qt widgets and controls in a qt widget. As I understand this can either be done in C++ code (by using layout managers like gridlayoutmanager or VerticalBoxlayoutmanager etc) or using .ui files. Can someone please tell me which is the recommended way? I came to hear that .ui files is an old way of doing things and we should not use them? Is that accurate? Should we prefer to have layout set in code rather than in .ui file?



  • The UI files are just a simpler/visual way of creating the same layout managers. Unless your layout needs to be generated on the fly based on variables (platform, screen resolution, screen orientation, ...) the easier/better way to go is using UI files - Qt creator will make much easier for you to create the ui.

    Some people are erroneously referring to widgets as obsolete because the new recommended way of doing UI for mobile devices is QML. Widgets haven't been discontinued and probably will not any time soon - they are still the recommended way to develop qt applications for desktop platforms and are perfectly fine for several mobile applications.



  • Check out the lesson nº3 in the "Qt in Education Course Material":http://qt.nokia.com/services-partners/qt-in-education/qt-in-education-course-material I find it very useful



  • I've split off the rest of this thread to "[SPLIT] Future of Widgets in Qt":http://developer.qt.nokia.com/forums/viewthread/3070/ in the general forum, as it was a topic of its own.

    But I do not want to steal "Andre's":http://developer.qt.nokia.com/member/438 valuable answer:

    [quote author="Andre" date="1294393121"] --- start ---[/quote]
    You can freely mix approaches using .ui files and hand crafted layouts even. Both have advantages and uses. If your layout is not going to be dynamic, I'd recommend using .ui files. They are not considdered "the old way" or anything like that.

    While fcochik is right, and QWidgets are not depricated, they don't currently have the focus of the Trolls anymore. Issues on Jira are being closed because of this, for instance. Still, for many situations, I think QWidgets are still way more suitable than QML. QML is nice for highly flashy UI, with smooth animations and the likes, but not so much for the typical desktop app with lots of input, buttons, menus, etc.
    [quote author="Andre" date="1294393121"] --- end ---[/quote]





  • My opinion is that there is no generic Best way of "layout-ing" the widgets.

    In the end both methods are going to be C++ code (most likely very similar C++ code).

    The only big difference is who is writing the C++ code you write it, or the UIC generate it (using the designer xml as a "pattern").

    If you want to check this just open an ui_UIFILENAME.h and see the implementation of the setupUi(...) method.

    So to choose one way or the other, you need to think of what is convenient for you: the time you need to write the code for Widgets/Layouts vs the time you need to achieve the same result using Designer.
    Basically is the same for the application/code/compiler, it only depends on what is convenient for you: what are you most productive with, or what do you like, or maybe some simple dialogs (with simple layouts) are fast to code and some more complex layouts are easier to implement in the Designer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.