I want to reuse parts of Qt layout between different widgets/windows/dialogs and have the reused parts respect the layout spacing of the top-level widget's layout.
For reusing parts I currently create separate classes derived from QWidget
for the parts I want to reuse (each having their own layout). However, when nesting widgets with their own layout instead the nested widgets get a content-margin of their own and have a spacing of their own. They will not respect the spacing of the parent widget's layout.
In Qt, it's possible to nested layouts, which gives a content-margin around the outside, and equal spacing between widgets. All widgets have the same parent (the main widget/window), and only the layouts are nested. Spacing is inherited to sub-layouts.
Is there a way to achieve this while reusing parts of the layout, so that the nested parts respect the spacing of the parent layout?
Alternatively, can I detect when the widget is inserted into a layout and apply the parent's layout's properties instead of using the defaults?