Add a widget to a horizontal box layout without moving everything else in the layout
-
Hello!
I want a button to popup a (self-created) widget on the left side. At the moment my button is in a horizontal layout with three labels. I want my menu to be in that layout so it gets resized depending on the resolution of the window. But when I hide/show my menu it frees it space and everything in the layout moves because the available space changes.
Is there a way to fix this?
Thanks!Note:
I cant use QMenu due to its limitated styling (top-level widget). -
@VogelPapaFinn Hi, did you try to use a stretch in your layout ?
QLayout::addStretch()
or Horizontal Spacer in Designer. It should take the empty space when you hide your widget. -
@VogelPapaFinn Did you set the stretch on first column ?
can't you put the spacer at the left so it pushes everything on the right ? -
First add an horizontal layout then add a spacer and your 'menu'
-
@mpergand theoretically it would do the same, wouldnt it?
I found another solution: As parent I choose the parent of the vertical layout my button is in. Then I just set it to the position of the button. But now I encounter a new problem: How do I override the resize event of the window? When I resize the window my menu stays at the same position in the middle of the screen. -
@VogelPapaFinn You should use a layout for your main window. Don't position your widgets manually.