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
Forum Updated to NodeBB v4.3 + New Features

Load/Render UI inside MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 935 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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
    1
    • mrjjM mrjj

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

      mrjjM 1 Reply Last reply
      0
      • F fem_dev

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

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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 ?

        JonBJ F 2 Replies Last reply
        0
        • mrjjM mrjj

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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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.

          mrjjM 1 Reply Last reply
          0
          • JonBJ JonB

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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            1
            • mrjjM mrjj

              @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 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
              • mrjjM mrjj

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

                mrjjM 1 Reply Last reply
                0
                • F fem_dev

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 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
                  2
                  • mrjjM mrjj

                    @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 last edited by
                    #10

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

                    JonBJ 1 Reply Last reply
                    0
                    • F fem_dev

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

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on 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

                      • Login

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