Make QHorizontalLayout expand inside QFrame

2019-08-06 13:40发布

问题:

I have a widget hierarchy like this, with a frame (in order to set a background color behind the buttons and label) and a horizontal layout as its direct child.

However, the horizontal layout (red frame in below screenshot of Qt Designer) does not take up the whole space inside the frame. How can I do that? Changing the property "layoutSizeConstraint" does not work. The label is already set to "Expanding" in horizontal direction, but still it keeps its size – I can resize the horizontal layout manually, but it should fill the width automatically.

回答1:

Your frame frame doesn't have a layout (it's shown on its icon in the tree). It's because you have added new QHBoxLayout and dragged it into a frame. You should remove this layout, drag the label and buttons to the frame, then open frame's context menu and choose "Layout" option and choose desired layout.