Remove spacing / margin / border between Widgets
-
Hello,
how can i remove the spacing between widgets?
One case is between the nested widgets (blue arrow - QTabWidget inside a QDockWidget)
The other case is between neighboring widgets (red arrow - QDockWidget side to side another QDockWidget)i have tried setting all the margins /spacing to zero as well as setting the border by stylesheet, but the space does not go away
layout->setSpacing(0); layout->setMargin(0); layout->setContentsMargins (0, 0, 0, 0); widget->setStyleSheet("border: 0px");
The optimal case would be that the border lines merge into one single line in both cases.
-
@gde23
those are the borders of the widget. Those are drawn by the specific platform style.
You can use stylesheets to remove the borders (and also set the background). e.g.QWidget { border: 0; background: white; }
But probably you want to do it specifically for certain widegts. -
@gde23
When you use aQDockWidget
, you automatically get a splitter when it is docked, so that you can resize it. It is this splitter that gives you the space between the dock and the other partition of your layout.
You can change the size of this splitter (called aseparator
in this context) using a stylesheet on theMainWindow
(herethis
, as I did it in the constructor ofMainWindow
).
Along with the border setting on theQTabWidget
pane
element, this gives:ui->tabWidget->setStyleSheet("QTabWidget::pane { border: 0; }"); this->setStyleSheet("QMainWindow::separator {width: 1px; border: none;}");
You need at least 1px otherwise you can't resize the dock.
The result on my system is: