How to remove the margin between QWidgets in layout
-
mainLayout->setContentsMargins(0,0,0,0);
This can't remove the margin in the center.here is my code:
QWidget* titleBar = new QWidget(this); QHBoxLayout* hLayout = new QHBoxLayout(); QLabel* mTitle = new QLabel("hgis"); hLayout->addWidget(mTitle); hLayout->addStretch(); titleBar->setLayout(hLayout); titleBar->setStyleSheet("background-color:blue;"); // QMainWindow* coreWidget = new QMainWindow(this); coreWidget->menuBar()->addAction(new QAction(QString("test1"),this)); coreWidget->setWindowFlags(Qt::FramelessWindowHint); coreWidget->setStyleSheet("background-color:black;margin: 0px;"); // QVBoxLayout* mainLayout = new QVBoxLayout(); mainLayout->addWidget(titleBar); mainLayout->addWidget(coreWidget); mainLayout->setContentsMargins(0,0,0,0); setLayout(mainLayout); setStyleSheet("background-color:red;");
I want to remove the red line between QLabel and QMainwindow.
-
mainLayout->setContentsMargins(0,0,0,0);
This can't remove the margin in the center.here is my code:
QWidget* titleBar = new QWidget(this); QHBoxLayout* hLayout = new QHBoxLayout(); QLabel* mTitle = new QLabel("hgis"); hLayout->addWidget(mTitle); hLayout->addStretch(); titleBar->setLayout(hLayout); titleBar->setStyleSheet("background-color:blue;"); // QMainWindow* coreWidget = new QMainWindow(this); coreWidget->menuBar()->addAction(new QAction(QString("test1"),this)); coreWidget->setWindowFlags(Qt::FramelessWindowHint); coreWidget->setStyleSheet("background-color:black;margin: 0px;"); // QVBoxLayout* mainLayout = new QVBoxLayout(); mainLayout->addWidget(titleBar); mainLayout->addWidget(coreWidget); mainLayout->setContentsMargins(0,0,0,0); setLayout(mainLayout); setStyleSheet("background-color:red;");
I want to remove the red line between QLabel and QMainwindow.
Hi @DDWW and Welcome,
setSpacing formainLayout
to0
. -
Margin is the space around the content. Item spacing is controlled like this:
mainLayout->setSpacing(0);
-
Hi @DDWW and Welcome,
setSpacing formainLayout
to0
.