Recommended way to implement properties window in QML
-
What is the recommended/good way to implement a properties window like the one in visual studio and Qt creator. My goal is to convert a winforms based editor into qml and currently I'm looking at how to best rebuild this
!http://www.plane9.com/content/wiki/portswin.png(property window)!
So each line on the screenshot is a dynamic control based and the whole window will change based on the node selected in the program. -
That looks like a TableView with the left column holding the property name, and the right a type-dependent editor.
-
How do you handle the runtime created editor in the best way? The ideal system would be that you have a c++ model that is basically a list of objects. Each object has a name and a type. Then depending on the type of object can also contain other data like a value for a int or a bool for a checkbox.
You feed that to a control and it would create all rows as shown above and also create a matching editor based on the type.
This is the part that I wonder what a good way is. How can I let QML create the controls dynamically based on the model and also allow the created controls to update the model objects as the user changes the data (That is clicks the checkbox, enters a new value, ...) -
I would use a Loader in the delegate, setting the source or sourceComponent property to select the correct editor based on the the model element's type property.
Another option is to include all possible editors directly in the delegate, and hide all but the correct editor depending on the type.
-
After some digging those are the two recommended ways I have found as well. Even though the hiding option apparently performs quite bad when you start to add more controls to the property window. So the loader seems to be the way to go.
I did look into the QtCreator source they however seem to build up the control from text strings that are the individual components. Then they send the completed test to the Qml engine to build up all controls. Probably the most efficient way but it certainly doesn't seem to be simple or easy to maintain.