PyQt - Reducing margins and spacing in widget *expands* layout

Firstly: setMargin is an obsolete method which has beed superseded by setContentsMargins, so you can ignore it.

Secondly: the increase in separation is caused by setting the margins to zero. The two vertical layouts are in the same horizontal layout, so they will necessarily have the same height. But the left-hand layout has no margins, so it has more space available to stretch out in. If both vertical layouts have the same settings, their child widgets can be squeezed closer together by resizing the window.

So you need to use setSpacing on both layouts to change the spacing.


In the latest PyQt 5.10 setContentsMargins method is working well. You may create a layout for your widget and then apply its margins.

widget.layout.setContentsMargins(0,0,0,0)