【发布时间】:2013-12-25 08:43:04
【问题描述】:
我目前正在使用 QMainWindow 小部件,我想删除内部小部件周围的边距。我成功删除了窗口边框的边距,但没有删除窗口内的小部件。
这是我的代码,例如:
this->mainWidget = new QWidget(this);
this->mainLayout = new QHBoxLayout;
QLabel *foo = new QLabel("foo", this);
QLabel *bar = new QLabel("bar", this);
mainLayout->setContentsMargins(0, 0, 0, 0); // Remove margins for window borders
this->setWindowFlags(Qt::FramelessWindowHint);
foo->setStyleSheet("background-color: green");
bar->setStyleSheet("background-color: red");
foo->setContentsMargins(0, 0, 0, 0); // Has no effect
bar->setContentsMargins(0, 0, 0, 0); // Has no effect
this->mainLayout->addWidget(foo);
this->mainLayout->addWidget(bar);
this->mainWidget->setLayout(mainLayout);
this->setCentralWidget(mainWidget);
这是它呈现的内容:
我想去掉两个小部件之间的白色部分。
你知道如何制作这种东西吗?
谢谢。
【问题讨论】:
-
旁注:您对所有成员访问使用
this->...,除了一个(mainLayout 的 setContentMargin) - 要么全部执行,要么不执行,但只留下没有显式限定看起来很奇怪 - 让你想知道我们是否在谈论两个不同的事情。