need to modify layout fill policy
-
I've got a QVBoxLayout that can contain up to four mixer widgets. Well, it always contains them, but only the active mixers are visible. Problem I currently have is that the layout makes use of space by uniformly placing the mixers in the frame. If all four are visible then the display is correct, but if only one is visible then it is places midway between top and bottom. I want to weight the fill of the layout so that space is filled from top to bottom and continue to use setVisible() to indicate which mixers are active. I don't see a fill policy setting under the layout properties. Is there a non-hackish way to easily accomplish this?
-
Try to set the vertical size policy to "Expanding"
BTW, I made a test with QFrame and the standard beheavior is what you want, if only one frame is visible, it occupies the all space.
@mpergand said in need to modify layout fill policy:
Try to set the vertical size policy to "Expanding"
no joy. size policies of the widgets in the layout make no difference. I did locate a "layout alignment" option in the designer pulldown, but regardless of what I do, it only wants to apply to the first (top) mixer widget, the remaining mixers continue to be added spaced out instead of top aligned.
Attached is the relevant widget tree. Each MixBar has its alignment alignment set to "top".
second image is what it looks like, which is wrong.
-
Try to set the vertical size policy to "Expanding"
BTW, I made a test with QFrame and the standard beheavior is what you want, if only one frame is visible, it occupies the all space.
@mpergand said in need to modify layout fill policy:
BTW, I made a test with QFrame and the standard beheavior is what you want, if only one frame is visible, it occupies the all space.
Actually that is opposite of what I want. I want it to only occupy necessary space, and align to the top of the container.
-
@mpergand said in need to modify layout fill policy:
BTW, I made a test with QFrame and the standard beheavior is what you want, if only one frame is visible, it occupies the all space.
Actually that is opposite of what I want. I want it to only occupy necessary space, and align to the top of the container.
@Kent-Dorfman I always fight with the QLayouts myself especially in the case you describe.
I would suggest, adding a 5th item to the layout, a QSpacer, that should expand and take up the available space from the hidden widgets
-
@mpergand said in need to modify layout fill policy:
BTW, I made a test with QFrame and the standard beheavior is what you want, if only one frame is visible, it occupies the all space.
Actually that is opposite of what I want. I want it to only occupy necessary space, and align to the top of the container.
@Kent-Dorfman said in need to modify layout fill policy:
Actually that is opposite of what I want. I want it to only occupy necessary space, and align to the top of the container.
In this case, add a spacer as @J-Hilk suggested.
-
@Kent-Dorfman I always fight with the QLayouts myself especially in the case you describe.
I would suggest, adding a 5th item to the layout, a QSpacer, that should expand and take up the available space from the hidden widgets
@J-Hilk , @Kent-Dorfman
I agree that with Qt it seems best to add an extra item at the end (vertically or horizontally), to cause previous stuff to "squeeze" into previous area. (Not that it seems ideal to me, but I think that's what peeps do.) However, you saidQSpacer
(I think that'sQSpacerItem
), I don't know whether the default is as small as possible? I would recommend void QBoxLayout::addStretch(int stretch = 0)? -
@J-Hilk , @Kent-Dorfman
I agree that with Qt it seems best to add an extra item at the end (vertically or horizontally), to cause previous stuff to "squeeze" into previous area. (Not that it seems ideal to me, but I think that's what peeps do.) However, you saidQSpacer
(I think that'sQSpacerItem
), I don't know whether the default is as small as possible? I would recommend void QBoxLayout::addStretch(int stretch = 0)?@JonB said in need to modify layout fill policy:
QSpacer (I think that's QSpacerItem),
I don't know for sure, I just added a Q before the Item description, you know, the Qt -way :D
-
Spacer at bottom?
Brilliant! Will give it a try and report back. ;^)
-
Spacer at bottom?
Brilliant! Will give it a try and report back. ;^)
-
inserting vertical spacer at bottom of layout did fix the problem Thanks!
and it wasn't as "hackish" as I had worried the solution would be. :^) -
inserting vertical spacer at bottom of layout did fix the problem Thanks!
and it wasn't as "hackish" as I had worried the solution would be. :^)@Kent-Dorfman
This question does get asked many times. ISTM that layouts should offer the functionality without user having to put a space/stretch at the other end of the layout to achieve this. I should be able to say "align/place all things from left/right/top/bottom one after the other, do not expand/move them", it's pretty common to want this....