Set content margins from stylesheet
Asked Answered
E

2

8

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.

Explode answered 29/11, 2012 at 19:28 Comment(7)
Just use qt designer for that.Fetter
i don't whant to use qt designer, that's not a solution, that's a workaround...Explode
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.Fetter
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...Explode
setStyleSheet(QLayout{ //css here })Fetter
Well, i told you, it is not working... if you have an exemple proving me wrong, you're welcome to post it.Explode
If you would have done proper research you would have know that its not possible to set stylesheets to QLayout objects and you wouldnt have asked this question. Furthermore there is a way in designer to set the content margins but you seem to ignore that too.Fetter
B
4

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.

Blueweed answered 21/7, 2014 at 16:20 Comment(0)
G
2

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.

Gilmore answered 16/1, 2013 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.