这是我的申请。对于这个问题,请忽略顶部的按钮。
我有一个QScrollArea
充满了许多QGroupBox
填充QLabel(左侧)和QGroupBox(右侧)的水平框布局
右侧是QPushButtons的垂直框布局
每个元素,scrollarea,两个框,标签和按钮都修改了样式表,因此填充为0px,边距为0px。
为什么我有这些额外的空间?
滚动区域的四周都有空间,直到其内部元素(蓝色框)开始。然后这些盒子有空间,直到它的内部元素(白色盒子)开始。
有人可以告诉我发生了什么事吗?
答案 0 :(得分:2)
为什么我有这些额外的空间?
如果我找对您,您需要使用此编辑布局代码,以排除不需要的空格:
QVBoxLayout *buttonsLayout = new QVBoxLayout;
buttonsLayout->setContentsMargins(0, 0, 0, 0); // remove spaces
buttonsLayout->setSpacing(0);
buttonsLayout->addWidget(daysButton);
...
答案 1 :(得分:0)
抓住QScrollArea的布局
QLayout *layout = myScrollArea->layout();
layout->setSpacing(0);
layout->setContentsMargins ( 0, 0, 0, 0 );