Qt Desktop development best practices



  • Hi, All

    I'm new in Qt, and both in c++ :-)
    I'm working on a project where I would need the following:

    • widget components needed: tabs, trees, picture, slider
    • many events to handle in a window (buttons to change picture, checkbox to activate/inactivate set of other widgets, etc)
    • custom components needed (tri-state buttons, label to show slider's current value, etc)

    If possible I would like to put all the behaviour into component declaration and position them in the wysiwyg editor.

    The Scenarios I tried:

    1. cpp with .UI descriptors

    PROS:

    • many default components to use with wysiwyg editor
    • native cpp (no integration needed)

    CONS:

    • cannot make custom components (and use them in wysiwg editor)
    • by default every behaviur (slot) goes to MainWindow.cpp - at least QtDesigner generates them there (ugly code, hard to maintain)

    2. QML

    PROS:

    CONS:

    Any suggestions how should I overcome to theese difficulties? Any best practices? Anything I'm missing?

    UPDATE: There is a promising desktop components project for QML (Qt Quick) under construction: http://blog.qt.digia.com/blog/2012/06/06/desktop-components-for-qt-5/
    I don't see too much information about them...

    Regards:
    Bence



  • Hi,

    bq. CONS:
    cannot make custom components (and use them in wysiwg editor)
    every behaviour should go to MainWindow.cpp (ugly code, hard to maintain)

    may be you missed that: "Creating Custom Widgets for Qt Designer":http://qt-project.org/doc/qt-5.0/qtdesigner/designer-creating-custom-widgets.html

    to be honest I don't get this: "every behaviour should go to MainWindow.cpp " ?



  • Hi

    [quote author="NicuPopescu" date="1382009993"]
    to be honest I don't get this: "every behaviour should go to MainWindow.cpp " ?[/quote]

    By default QtDesigner generates widget declaration and structure into ui-mainwindow.h and the slots into mainwindow.cpp. So if you want to give some behavior to your widgets (e.g. define listener/slot to handle pushbutton event/signal) it is defined in mainwindow.cpp by default. Or is there another way to do that?

    Regards.
    Bence



  • When a "chunk" of widgets are used inside a "global" widget your also able to create the child widget in a stand alone designer form and connect all signals/slots inside this widget, but that might go a bit too deep for you here if your new.
    MainWindow is the place to "dump" it all until your ready to refract.



  • The best way I see:
    http://www.youtube.com/watch?v=Yt-YCxgEnyw
    http://qt-project.org/forums/viewthread/6536

    The same as Jeroentje suggested. The only drawback is that the "child" widget is displayed as an empty QFrame inside its "parent" in QtDesigner. in runtime it's ok... This way it is quite challenging to position and size the widgets.

    Is three a way to solve this?



  • bq. By default QtDesigner generates widget declaration and structure into ui-mainwindow.h and the slots into mainwindow.cpp. So if you want to give some behavior to your widgets (e.g. define listener/slot to handle pushbutton event/signal) it is defined in mainwindow.cpp by default. Or is there another way to do that?

    have you seen other frameworks/IDEs doing this in different way? i.e. as far as I know Visual Studio adds event handlers in the same view .cpp for MFC, .NET/C#/VB etc. and it's up to the programmer to separate the creation code from the one implementing the behavior



  • [quote author="NicuPopescu" date="1382025186"]have you seen other frameworks/IDEs doing this in different way? i.e. as far as I know Visual Studio adds event handlers in the same view .cpp for MFC, .NET/C#/VB etc. and it's up to the programmer to separate the creation code from the one implementing the behavior[/quote]

    For example Qt itself :-) See solution above: it works well, and seems to be a much better scenario than putting every event-handling code into mainwindow.cpp.


  • Moderators

    [quote author="bence.takacs" date="1382008853"]
    2. QML

    ...

    CONS:

    ...

    UPDATE: There is a promising desktop components project for QML (Qt Quick) under construction: http://blog.qt.digia.com/blog/2012/06/06/desktop-components-for-qt-5/
    I don't see too much information about them...[/quote]The desktop components, with buttons and gradients and sliders, were released with Qt 5.1: http://qt-project.org/doc/qt-5.1/qtquickcontrols/qtquickcontrols-index.html

    I've also added some new findings to your QML tabs thread. Have a look; hopefully you'll find QML tabs usable now.



  • Yes, thanks :-)

    It seems much better. Nevertheless I choose the CPP with QtDesigner scenario.


  • Moderators

    C++ widgets are more mature than Qt Quick, like you said. All the best with your project!



  • The following scenario works fine for me:

    Using Qt Designer for creating the main design for the page. If I need a custom component I choose from the following solutions:

    Simply extending an existing QWidget - if i need to extend the functionality of a simple widget, this is the best solution

    Creating a Qt Designer Form class extending a QFrame - this way I can put separate objects into the frame, position them and wire them together (with signals and slots) - good for creating composite components

    ... and at last i can put a new widget into the page (it needs to be the same type as the ancestor of our custom widget) and promote that to the custom component.

    One issue: In case of the 2nd solution (Form) Qt Designer don't show the real appearance of the widget, so I need to position and layout that blind, but this is a small price for that.


Log in to reply
 

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