PDA

View Full Version : QLabel top and bottom padding is not getting set to zero.



Vinaya
8th February 2017, 22:15
Hello,

I am trying to make the top and bottom padding zero in my QLabel. I have tried all the options below but none of them seem to work.
Am i missing something? In smaller fonts, the padding is negligible. As the font size increases(in my case 192 Sans Serif), the top and bottom padding are too big to ignore.

QLabel *newLabel = new QLabel("Text", this);
this->setStyleSheet("QLabel { border: 0px; }");
newLabel->setAlignment(Qt::AlignTop);
newLabel->setStyleSheet("background-color: yellow; color: blue; font-size: 192px; padding: 0 0 0 0px; border: 0 0 0 0px");
newLabel->setIndent(0);
newLabel->setMargin(0);
newLabel->setContentsMargins(0, 0, 0, 0);
newLabel->setFrameShape(QFrame::HLine);
newLabel->setFrameStyle(QFrame::NoFrame);


Is there anything I must try?
Any help would be greatly appreciated as this is really bothering me.

Thank you.

d_stranz
9th February 2017, 21:52
Maybe it isn't the label at all, but the layout or other place where you are embedding it?

Vinaya
9th February 2017, 22:40
Hello,

Thanks for your response
I've tried setting the layout and the central Widgets contents Margins to zero as well. That doesn't help. This can be seen in a simple qt app which has two labels.

Added after 4 minutes:

Also, yesterday i tried to set negative padding which works, so I'm convinced it has something to do with the label. However, I am not sure if that's a good idea as the font size is configurable.

masotrix
17th October 2019, 14:35
Hello,

Thanks for your response
I've tried setting the layout and the central Widgets contents Margins to zero as well. That doesn't help. This can be seen in a simple qt app which has two labels.

Added after 4 minutes:

Also, yesterday i tried to set negative padding which works, so I'm convinced it has something to do with the label. However, I am not sure if that's a good idea as the font size is configurable.


Strange, I had sort of the same problem and layout.setContentsMargin(0,0,0,0) solved it