I have a widget in designer that has a fairly complex layout. It has a main VBoxLayout with various other layouts inside of it, including an HBoxLayout that contains two QGroupBoxes. I want to make each of the group boxes occupy the same amount of width withn the HBoxLayout. To do this, I want to set the horizontal stretch factor on the layout for each of the group boxes.

In order to do this, I need to get a pointer to the layout containing the group boxes. Currently, I just found the name of the layout variable in the generated ui_*.h file and set the stretch factor on it. This seems pretty fragile since the variable name is generated. If someone changes the .ui file, it seems to me that this variable name may be regenerated differently the next time the .ui file is compiled. Is there anyway to avoid this?

Is there a way to get the layout that contains a widget? QWidget::layout() gives you the layout contained in a widget, but I want the opposite. Calling parent()->layout() doesn't work because the HBoxLayout that I want is actually nested within the parent()->layout().

Any ideas? Thanks