Question

It´s just a container and i want to put widgets inside and hide them and show them. I don´t want it to have any margins or paddings, and it will be invisible (no border, no background)

I set the QWidget#container to margin:0px, padding:0px through a stylesheet. And setObjectName("container") to all the widgets that contain.

Nothing happens. But setting a background color works, so it is executed.

In which cases does this happen? How to fix this?

Was it helpful?

Solution

QWidget does not support box model, so it does not understand padding/margin CSS directives. Use QFrame as container. To see which widgets support box model take a look at list of stylable widgets

OTHER TIPS

Given there was no concise answer I'll sum up the above:

To create a container with no margins and padding, instead of QWidget, use QFrame, and set a layout on it. Then set the spacing to 0 and set the content margins to 0 as well on the layout. Using a stylesheet setting padding/margin to 0 will have no effect.

Code:


QFrame* containerFrame = new QFrame();
QVBoxLayout* layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
// add some widgets to the layout
containerFrame->setLayout(layout);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top