[英]Qt remove margins
我目前正在使用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->setSpacing(0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.