QGridLayout / QVBoxLayout- have a widget disappear when not enough space?
-
Hi there,
im new to QLayouts and just started learning them. As a challenge im trying to emulate some UI.
Ive got a parent widget which may be resized. It contains 2 child widgets. The top row widget is required to take at least 80 pixels in space. The bottom widget can take as much leftover as it likes, as long as the parent widget is at least 80 pixels in size.
The top widget can also resize but only when we reach below 80 pixels.
So:
Parent widget 30 pixels => Only top widget shows, 30 pixels in height
Parent widget 80 pixels => Only top widget shows, 80 pixels in height
Parent widget 120 pixels => Top widget 80 pixels in height, bottom widget 40 pixels in height.No matter what I try, the bottom widget always takes at least 1 pixel of space. I want it to vanish completely. Is this possible? or what would the most elegant way to do this be?
Thanks :) Am using QT 6.5
-
Hi there,
im new to QLayouts and just started learning them. As a challenge im trying to emulate some UI.
Ive got a parent widget which may be resized. It contains 2 child widgets. The top row widget is required to take at least 80 pixels in space. The bottom widget can take as much leftover as it likes, as long as the parent widget is at least 80 pixels in size.
The top widget can also resize but only when we reach below 80 pixels.
So:
Parent widget 30 pixels => Only top widget shows, 30 pixels in height
Parent widget 80 pixels => Only top widget shows, 80 pixels in height
Parent widget 120 pixels => Top widget 80 pixels in height, bottom widget 40 pixels in height.No matter what I try, the bottom widget always takes at least 1 pixel of space. I want it to vanish completely. Is this possible? or what would the most elegant way to do this be?
Thanks :) Am using QT 6.5
@NightShadeI
Could you post the code creating the widgets and layouts? -
There isn't really code as such as none of the many things I have tried have worked. I'm more asking for what WILL work.
I've discovered the issue is my content margins in the 2nd row (there is a nested QGridLayout). If I set the nested QGridLayout in the 2nd row to have content margins of all zero it works.
I don't want to have to do this , and still want some way to have the top 80 pixels for the top row only , even if it means the 2nd widget goes out of drawing view.
-
There isn't really code as such as none of the many things I have tried have worked. I'm more asking for what WILL work.
I've discovered the issue is my content margins in the 2nd row (there is a nested QGridLayout). If I set the nested QGridLayout in the 2nd row to have content margins of all zero it works.
I don't want to have to do this , and still want some way to have the top 80 pixels for the top row only , even if it means the 2nd widget goes out of drawing view.
This is the workaround I was able to end up doing
class ZeroSpaceGrid : public QGridLayout { public: explicit ZeroSpaceGrid(QWidget* aParent) : QGridLayout{aParent} {} QSize minimumSize() const final { return QSize{0, 0}; } };
I don't like it though. Surely there must be a nicer way to have 2 rows of items, and not have the one with content margins stick around constantly given its min size is non-zero? This feels a hit hacky.