Remove spacing / margin / border between Widgets



  • Hello,

    how can i remove the spacing between widgets?

    alt text

    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.


  • Moderators

    @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 a QDockWidget, 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 a separator in this context) using a stylesheet on the MainWindow (here this, as I did it in the constructor of MainWindow).
    Along with the border setting on the QTabWidget 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:

    0_1521570026042_05d348f9-2d5d-4729-80da-60dbb43384d1-image.png


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.