Load/Render UI inside MainWindow
-
wrote on 18 Dec 2019, 17:42 last edited by
I have a Qt Widgets application with 3 main GUI areas, like this image below:
- Item menu
- Load UI Area
- Console
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 theLoad UI area
when the user clicks in theitem x
?
b) Is there another good way to load these properties GUI inside theLoad UI Area
? -
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.htmlint 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); ... }
-
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.htmlint 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); ... }
wrote on 18 Dec 2019, 18:24 last edited by@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?
-
@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?
@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 ?
-
@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 ?
wrote on 18 Dec 2019, 18:47 last edited by@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.
-
@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.
@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. -
@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 ?
wrote on 18 Dec 2019, 19:59 last edited by@mrjj Each item type is not only fill Line Edits....
Each item type has another input fields likecheckboxes
,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"... -
@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.wrote on 18 Dec 2019, 20:03 last edited by@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?
-
@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?
@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.
-
@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.
-
wrote on 19 Dec 2019, 07:51 last edited by
1/11