8
votes

I'm struggling to set content margins to zero from QLayout objects in Qt with a stylesheet. I can remove them with QLayout::setContentsMargins(0, 0, 0, 0) but I would prefer to do it from stylesheet.

2
Just use qt designer for that. - fonZ
i don't whant to use qt designer, that's not a solution, that's a workaround... - Ben
Its not because you can set the stylesheet as wel as the margins in there. So basically it does EXACTLY what you want to achieve. Everything else can be found in the Qt documentation. - fonZ
I know i can do it in QT designer as well as i can do it with the setContentsMargins() method, but i'd like to be able to do it with a stylesheet... - Ben
setStyleSheet(QLayout{ //css here }) - fonZ

2 Answers

4
votes

As of now this cannot be achieved. Use

QLayout::setContentsMargins(0, 0, 0, 0)

and

QLayout::setSpacing(0)

if you also want to eliminate the space between widgets.

See also this bug report Stylesheet controls for QLayout objects which is unresolved so far.

2
votes

It is not possible to set a stylesheet for a QLayout, use a QWidget instead, in which you will set a layout. Then, you can set the margin and/or padding of your widget with stylesheet to match you needs.