Qt边距/小部件之间的间距

Slo*_*lot 5 c++ layout qt

我想管理我的小部件之间的空间,verticaly和horizo​​ntaly.

这是一张说明我想要的图片:

在此输入图像描述

当我点击红点时,我想减少/扩展红线所在的空间(垂直).

当我点击蓝点时,我想缩小/扩展蓝线所在的空间(水平).

我的架构是这样的:

一个带有布局的主Widget,其中包含左/右箭头按钮和所有白色视图的QWidget.

这个QWidget包含一个QGridLayout.在这个QGridLayout中,我有"左","后"......小部件(截图中为白色).

  • 带有布局的QWidget
    • 左箭头
    • 右箭头
    • 带有QGridLayout的QWidget(GRIDLAYOUT)
      • 带有VBoxLayout和2个标签的QWidget.(视图)

我试着设置VIEW-> setContentsMargins(); 但是白色矩形保持不变,只有这个矩形内的间距发生变化(例如边框和"左"标签之间的距离(屏幕上的1和2)).

我还尝试设置GRIDLAYOUT-> setContentsMargins(); 但这次只有屏幕上3号和4号的间距发生变化.

显然,水平调整大小有相同的行为.(截图上的蓝色标记.

间距不允许分别管理垂直和水平间距......

我希望你理解我试图解释的内容:o

我该怎么办呢?

先感谢您,

Seb*_*nge 6

For managing the space inbetween the white rects you can easily use

QGridLayout()::setHorizontalSpacing(int spacing);
QGridLayout()::setVerticalSpacing(int spacing);
Run Code Online (Sandbox Code Playgroud)

This will set up the space between the white rects but not the space between white rect and border of upper widget. For these you will have to use (inherited from QLayout):

QGridLayout()::setContentsMargins ( int left, int top, int right, int bottom )
Run Code Online (Sandbox Code Playgroud)