Make QHorizontalLayout expand inside QFrame

2019-08-06 13:39发布

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.

Widget hierarchy

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.

Layout not expanded

1条回答
▲ chillily
2楼-- · 2019-08-06 14:15

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.

查看更多
登录 后发表回答