Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Desktop development best practices
Forum Updated to NodeBB v4.3 + New Features

Qt Desktop development best practices

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bence.takacs
    wrote on last edited by
    #1

    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:

    • custom components suported and displayed well in wysiwyg editor
    • well-integrated with cpp (http://qt-project.org/forums/viewthread/33749/)

    CONS:

    • poor set of widgets (no button with roundings and gradient, no slider, etc)
    • widgets not mature enough (e.g. TreeView has more known basic issues: http://qt-project.org/forums/viewthread/30521, http://qt-project.org/forums/viewthread/33594/ and TabView also has problems: http://qt-project.org/forums/viewthread/33463/#146910)

    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

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      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 " ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bence.takacs
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          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.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bence.takacs
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NicuPopescu
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bence.takacs
                wrote on last edited by
                #7

                [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.

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

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

                  ...

                  CONS:

                  • poor set of widgets (no button with roundings and gradient, no slider, etc)
                  • widgets not mature enough (e.g. TreeView has more known basic issues: http://qt-project.org/forums/viewthread/30521, http://qt-project.org/forums/viewthread/33594/ and TabView also has problems: http://qt-project.org/forums/viewthread/33463/#146910)

                  ...

                  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.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bence.takacs
                    wrote on last edited by
                    #9

                    Yes, thanks :-)

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

                    1 Reply Last reply
                    0
                    • JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

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

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        bence.takacs
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved