Add a widget to a horizontal box layout without moving everything else in the layout
-
wrote on 11 Jul 2022, 20:46 last edited by
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). -
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).wrote on 12 Jul 2022, 18:05 last edited by@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 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.wrote on 12 Jul 2022, 20:55 last edited by@Gojir4 Hi!
QGridLayout::setColumnStretch()
doesnt work at all and a spacer pushes everything else to the left corner ._. -
@Gojir4 Hi!
QGridLayout::setColumnStretch()
doesnt work at all and a spacer pushes everything else to the left corner ._.wrote on 12 Jul 2022, 21:04 last edited by@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 ? -
@Gojir4 Hi!
QGridLayout::setColumnStretch()
doesnt work at all and a spacer pushes everything else to the left corner ._.wrote on 12 Jul 2022, 21:06 last edited by mpergand 7 Dec 2022, 21:07First add an horizontal layout then add a spacer and your 'menu'
-
First add an horizontal layout then add a spacer and your 'menu'
wrote on 12 Jul 2022, 21:19 last edited by VogelPapaFinn 7 Dec 2022, 21:20@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. -
@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.wrote on 12 Jul 2022, 21:39 last edited by@VogelPapaFinn You should use a layout for your main window. Don't position your widgets manually.
1/7