Visual Inheritance



  • In an app, there will be nearly identical forms, for example, a customer registration form and registration form for vendors will be very similar, but have a datagrid column's name will be different for each one, both buttons will save, delete and new , also existed labels as well as lineedits, which changed from one to the other is the amount and type of widget. In such suppliers can be lineedits instead of combobox. The window title and icon will be different.

    Well considering that there are some commonalities between the two Forms (customers and suppliers) would be interesting to create a base class containing common among the widgets to make visual inheritance? There are other entries that have the same designer, I believe that there would be a lot of code redundancy since these entries have a similar form. I say seemed because as I mentioned, there will be some differences such as the window title, icon, lineedits some have more than others.

    It would be feasible to have a base form, since it would be much different from each other (name of the columns in datagrid, much lineedits, the layout would be changed accordingly to organize a different amount if components, etc. ...). Does not the same thing to write everything from scratch in each one, as even using a base class so much change?

    Visual Inheritance works well in Qt?



  • One way to do this is to create a custom dialog and then expose the parts that need to differ between instantiations as properties. Then you can just make 2 instances and set the properties as needed for each. You could even abstract the differences into a single "Mode" enum property and the logic inside the class takes care of makign the necessary alterations.

    You could do it with actual inheritance too but this seems like more work and extra symbols for no real benefit.



  • What is your plan? Do you want to build your base form with Designer or hand coded?
    Hand coded:
    You can choose among all the C++ concepts to produce variants, subclassing or the strategy pattern come to my mind.

    Designer:
    Add a widget to your base form as a placeholder for differing variants.
    Save the base form many times and promte the widget to all the different specializations you need.



  • Ok, Thanks for the ideas, try to implement here.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.