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. Load/Render UI inside MainWindow

Load/Render UI inside MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 899 Views
  • 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.
  • F Offline
    F Offline
    fem_dev
    wrote on 18 Dec 2019, 17:42 last edited by
    #1

    I have a Qt Widgets application with 3 main GUI areas, like this image below:

    • Item menu
    • Load UI Area
    • Console

    837a6c63-a870-428f-89e5-a4c0f043abad-image.png

    In the left side, each item x will have some properties, but theses properties are not the same for each item type like (person and house), so they may not share the same input fields.

    So, to user fill (type) the item property, I think that I have to develop a custom user interface for each item type. Right?

    The questions are:
    a) How can I load a *.ui file inside the Load UI area when the user clicks in the item x?
    b) Is there another good way to load these properties GUI inside the Load UI Area?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 18 Dec 2019, 17:48 last edited by mrjj
      #2

      Hi
      Without know what the Item A,b,c really are its hard to give advice.
      But if the Items ABC etc are plain UI files with no .h or cpp. you can use
      https://doc.qt.io/qt-5/quiloader.html to load that UI as a widget to be shown.

      Regarding the different properties of each type.
      Qt has a property system and you can actually enumerate what a class has if its a QObject so its
      possible to write an editor that can do that without hardcoding which properties to edit.
      https://doc.qt.io/qt-5/properties.html

      int count = metaobject->propertyCount();
      for (int i=0; i<count; ++i) {
          QMetaProperty metaproperty = metaobject->property(i);
          const char *name = metaproperty.name();
          QVariant value = object->property(name);
          ...
      }
      
      F 1 Reply Last reply 18 Dec 2019, 18:24
      1
      • M mrjj
        18 Dec 2019, 17:48

        Hi
        Without know what the Item A,b,c really are its hard to give advice.
        But if the Items ABC etc are plain UI files with no .h or cpp. you can use
        https://doc.qt.io/qt-5/quiloader.html to load that UI as a widget to be shown.

        Regarding the different properties of each type.
        Qt has a property system and you can actually enumerate what a class has if its a QObject so its
        possible to write an editor that can do that without hardcoding which properties to edit.
        https://doc.qt.io/qt-5/properties.html

        int count = metaobject->propertyCount();
        for (int i=0; i<count; ++i) {
            QMetaProperty metaproperty = metaobject->property(i);
            const char *name = metaproperty.name();
            QVariant value = object->property(name);
            ...
        }
        
        F Offline
        F Offline
        fem_dev
        wrote on 18 Dec 2019, 18:24 last edited by
        #3

        @mrjj thank you for your quick response...

        Well, each item type (person, house, etc...) should be your own GUI to the user fill the properties input fields.

        I will need to have for each *.ui file the correspondent *.cpp and the *.h files to manage and validate the input fields.

        Example:

        • person.ui
        • person.cpp
        • person.h

        What is the best way to do that?

        M 1 Reply Last reply 18 Dec 2019, 18:34
        0
        • F fem_dev
          18 Dec 2019, 18:24

          @mrjj thank you for your quick response...

          Well, each item type (person, house, etc...) should be your own GUI to the user fill the properties input fields.

          I will need to have for each *.ui file the correspondent *.cpp and the *.h files to manage and validate the input fields.

          Example:

          • person.ui
          • person.cpp
          • person.h

          What is the best way to do that?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 18 Dec 2019, 18:34 last edited by mrjj
          #4

          @fem_dev
          Hi
          Well if you have many types and many properties, i would go with generic editor that
          would loop over the properties and dynamically add lineEdits/widgets to allow altering values.

          If you only have a few, it might be easier just to give them the needed fields and
          let them handling the editing themself pr UI file.

          Those Types, are those data items, or real Widgets with some other GUI than the editing part ?

          J F 2 Replies Last reply 18 Dec 2019, 18:47
          0
          • M mrjj
            18 Dec 2019, 18:34

            @fem_dev
            Hi
            Well if you have many types and many properties, i would go with generic editor that
            would loop over the properties and dynamically add lineEdits/widgets to allow altering values.

            If you only have a few, it might be easier just to give them the needed fields and
            let them handling the editing themself pr UI file.

            Those Types, are those data items, or real Widgets with some other GUI than the editing part ?

            J Offline
            J Offline
            JonB
            wrote on 18 Dec 2019, 18:47 last edited by
            #5

            @mrjj said in Load/Render UI inside MainWindow:

            Well if you have many types and many properties, i would go with generic editor that
            would loop over the properties and dynamically add lineEdits/widgets to allow altering values.

            For this a QDataWidgetMapper does the job for you, if you present your data as a Qt model.

            M 1 Reply Last reply 18 Dec 2019, 18:58
            0
            • J JonB
              18 Dec 2019, 18:47

              @mrjj said in Load/Render UI inside MainWindow:

              Well if you have many types and many properties, i would go with generic editor that
              would loop over the properties and dynamically add lineEdits/widgets to allow altering values.

              For this a QDataWidgetMapper does the job for you, if you present your data as a Qt model.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 18 Dec 2019, 18:58 last edited by
              #6

              @JonB
              Yes so that is why i want to know more about the
              types if they be data item or actual widgets.
              And if the editing of the data is besides some other GUI elements etc.

              You are right that ifs data classes, then a model would fit much better and
              gives all the editing for free.

              F 1 Reply Last reply 18 Dec 2019, 20:03
              1
              • M mrjj
                18 Dec 2019, 18:34

                @fem_dev
                Hi
                Well if you have many types and many properties, i would go with generic editor that
                would loop over the properties and dynamically add lineEdits/widgets to allow altering values.

                If you only have a few, it might be easier just to give them the needed fields and
                let them handling the editing themself pr UI file.

                Those Types, are those data items, or real Widgets with some other GUI than the editing part ?

                F Offline
                F Offline
                fem_dev
                wrote on 18 Dec 2019, 19:59 last edited by
                #7

                @mrjj Each item type is not only fill Line Edits....
                Each item type has another input fields like checkboxes, sliders, images, etc...So, I think that will be better to have a well defined GUI for each item type...and not use a "dynamic generic editor"...

                1 Reply Last reply
                0
                • M mrjj
                  18 Dec 2019, 18:58

                  @JonB
                  Yes so that is why i want to know more about the
                  types if they be data item or actual widgets.
                  And if the editing of the data is besides some other GUI elements etc.

                  You are right that ifs data classes, then a model would fit much better and
                  gives all the editing for free.

                  F Offline
                  F Offline
                  fem_dev
                  wrote on 18 Dec 2019, 20:03 last edited by
                  #8

                  @JonB Each item type is a Qt Widgets Class (so I have the *.ui and the *.cpp and *.h) to do the input data validation, save data, etc...

                  I think that will be good to load each Qt Widget class UI on the Load UI area, but I don't know how to do it.
                  And I don't know if this idea is the best way to do that.

                  Could you help me a little bit more?

                  M 1 Reply Last reply 18 Dec 2019, 20:15
                  0
                  • F fem_dev
                    18 Dec 2019, 20:03

                    @JonB Each item type is a Qt Widgets Class (so I have the *.ui and the *.cpp and *.h) to do the input data validation, save data, etc...

                    I think that will be good to load each Qt Widget class UI on the Load UI area, but I don't know how to do it.
                    And I don't know if this idea is the best way to do that.

                    Could you help me a little bit more?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 18 Dec 2019, 20:15 last edited by
                    #9

                    @fem_dev
                    Hi
                    Agree if many types of widgets needed for editing, then dynamic is not optimal.

                    If you have a fully defined UI + cpp and .h

                    you can simply new an instance and put it into the "Load UI Area"

                    You could use a QStackedWidget (as UI Area) to have a page for each type to avoid having to exchange them, and make switching fast.

                    F 1 Reply Last reply 18 Dec 2019, 20:33
                    2
                    • M mrjj
                      18 Dec 2019, 20:15

                      @fem_dev
                      Hi
                      Agree if many types of widgets needed for editing, then dynamic is not optimal.

                      If you have a fully defined UI + cpp and .h

                      you can simply new an instance and put it into the "Load UI Area"

                      You could use a QStackedWidget (as UI Area) to have a page for each type to avoid having to exchange them, and make switching fast.

                      F Offline
                      F Offline
                      fem_dev
                      wrote on 18 Dec 2019, 20:33 last edited by
                      #10

                      @mrjj thank you guys...I will try the QStackedWidget solution!

                      J 1 Reply Last reply 19 Dec 2019, 07:51
                      0
                      • F fem_dev
                        18 Dec 2019, 20:33

                        @mrjj thank you guys...I will try the QStackedWidget solution!

                        J Offline
                        J Offline
                        JonB
                        wrote on 19 Dec 2019, 07:51 last edited by
                        #11

                        @fem_dev
                        I'm sorry, I think we struggled to understand what exactly you were asking for here! As @mrjj has said, if you wish to choose between a number of widgets to place in a single area such that at any time only one is present, QStackedWidget is the way to go.

                        1 Reply Last reply
                        1

                        1/11

                        18 Dec 2019, 17:42

                        • Login

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