I have a label, and I set both padding in the style sheet and a margin using setMargin()
.
ui->label->setPixmap(redRectWithGreenBorder(80, 40));
ui->label->setStyleSheet("QLabel {border: 1px solid gray;border-radius: 2px;background-color: white;padding: 0px 5px 10px 15px;}");
ui->label->setMargin(5);
But this is how it looks in reality:
The visible margins are 5, 10, 15 and 20 (I checked with an image editor). That is, they are equal to the value of the style sheet for this side plus the value of margin()
, i.e. 0+5, 5+5, 10+5, 20+5.
However, the documentation says this about setMargin()
:
margin : int This property holds the width of the margin.
The margin is the distance between the innermost pixel of the frame and the outermost pixel of contents.
The default margin is 0.
If I were taking the documentation at face value, I would have expected the margin to be the real distance between the content and the border. But it is not. Instead, the sum of the margin and the style sheet padding is the real margin.
My question is, where in the documentation is this behavior described? Is there some other place in the documentation where this behavior is specified that I have missed?