Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Qt Stylesheet: Margins of childwidgets
I'm using qss to style my ui. I have a QMainWindow with a centralWidget and the centralwidget has a layout that contains widgets. If i set margins in qss for centralwidget, the widgets in the layout of the centralwidget do not recognize the margins. Whats wrong?
I see that the middle has the margins, but not the headerpanel i created. Some code:
mainLayout = new QVBoxLayout(this);
headerPanel = new BackgroundPanel(this);
mainLayout->addWidget(headerPanel, 1, Qt::AlignTop);
And this is the css:
background-position: bottom right;
Now, the header panel is at full size, no margins.
And here's a screen:
Any ideas? Or is it true that i have to set the margin for each widget
no ideas? Do i really have to set the margins for each widget? Also if it is a child of a widget with margins?
If I am not mistaken your style sheet is only for your MainCentralWidget so It won't apply to other widgets.
You have to make a more generic style sheet for QWidget for example and prepend it to your current style sheet.
Hope it helps
So...child widgets are not part of the style? I expected that if i set the margin of a widget, the child widget in the parent layout also has the margins.
It works if i set the the margins of the child-widget. I dont want to set the margin of QWidget because every Qwidget then has the margin...that's not what i want.
BTW: Thank you for your answer :-)
You're welcome :)
Basically no, each widget is independent for that.
You could however use this "technique":http://qt-project.org/doc/qt-5.0/qtwidgets/stylesheet-examples.html#customizing-using-dynamic-properties for your child widgets