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.
Set content margins from stylesheet
Asked Answered
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
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.
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.
© 2022 - 2024 — McMap. All rights reserved.