Management of many QGroupBox in a single QVBoxLayout
-
I am designing a GUI where the user will select a tree node. Depending on the type of node they select, I have a QVBoxLayout that will show a QGroupBox with various attributes that can be set for the node.
My question is, there are many different node types. Each will need to reconfigure the QVBoxLayout. My initial take on how to do this is load the QVBoxLayout with every node QGroupBox and just regulate what appears in the layout using the visibility state.
Is this a viable solution? Or would it be better to tear down the QVBoxLayuout and only make it contain what QGroupBox layout it needs for a given node? Any advice?
-
The answer is as usual: it depends.
One aspect here is the number of boxes. If it's a couple then it might be ok to keep them around hidden. If there are 50 of them it might be better to dynamically create/destroy them.
Of course another aspect is how complicated the boxes are. If they are complex you might not want to wait for building them every time you select a node. If they're simple it might be ok.I'd say measure, check and profile.
-
There probably will be 25-30 boxes. Some will be simple. Some will be complex.
Can I just allocate them all on startup and just add/remove them from QVBoxLayout as selection changes? So instead of hide/show mechanism. I do a remove/add.
Maybe its probably not a big deal to completely destroy them and reallocate them. I have a aversion to deleting items I know will be used frequently.
-
I can't tell you what's right for you. All mentioned solutions will do the job. Some are just better suited for one or another scenario.
Do it and see how it works. If it works for your scenario then it works ;)