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.

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Ben
  • 966
  • 2
  • 10
  • 24
  • Just use qt designer for that. – fonZ Nov 29 '12 at 21:35
  • 2
    i don't whant to use qt designer, that's not a solution, that's a workaround... – Ben Nov 29 '12 at 22:05
  • 1
    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 Nov 29 '12 at 22:07
  • 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 Nov 29 '12 at 22:20
  • setStyleSheet(QLayout{ //css here }) – fonZ Nov 29 '12 at 22:23
  • Well, i told you, it is not working... if you have an exemple proving me wrong, you're welcome to post it. – Ben Dec 02 '12 at 16:13
  • 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. – fonZ Dec 02 '12 at 16:37

2 Answers2

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.

Community
  • 1
  • 1
NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
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.

Kévin Renella
  • 1,007
  • 9
  • 20