Remove stretch in QVBoxLayout ?
-
Hello,
I have a QVBoxLayout with a QWidget added as central widget of my QMainWindow, with some QLabel in that QWidget. When I enlarge the QMainWindow in height, some stretch thingies can be seen between QLabel. I would like the QLabel to stick to the top and not have stretching between them when the height is bigger than their total height, is that possible?
(see picture)
Thanks ! -
Add a stretch at the end of the layout:
yourVBoxLayout->addStretch();
-
Thanks @Chris-Kawa, the issue with this is that when I add other QLabel dynamically throu a buttonit adds it after the stretch. see picture:
Actually I want to have the newest QLabel added at the top of the existing ones, then it would make sense to have the stretch at the bottom, like that, but I am not sure how I can add new widget at the top of other with QVBoxLayout, yet :D
-
Hi,
Rather than adding widgets, use insert and set the position to one before the last.
-
Our posts crossed each other :-)
It's another possibility yes.
-
you can create a layout and at the start add a stretch with layout.addstretch()
then instert the widget at position count() - 1, ie layout.insertwidget(layout.count()-1, widget, *args, **kwargs)