Results 1 to 4 of 4

Thread: QLabel top and bottom padding is not getting set to zero.

  1. #1
    Join Date
    Feb 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QLabel top and bottom padding is not getting set to zero.

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel top and bottom padding is not getting set to zero.

    Maybe it isn't the label at all, but the layout or other place where you are embedding it?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Feb 2017
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel top and bottom padding is not getting set to zero.

    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.
    Last edited by Vinaya; 9th February 2017 at 23:40.

  4. #4
    Join Date
    Oct 2019
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: QLabel top and bottom padding is not getting set to zero.

    Quote Originally Posted by Vinaya View Post
    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

Similar Threads

  1. Qwt: curve with padding
    By alperyazir in forum Qwt
    Replies: 1
    Last Post: 11th November 2014, 11:19
  2. Adding some padding to a button
    By scarleton in forum Qt Programming
    Replies: 1
    Last Post: 12th June 2010, 16:18
  3. Replies: 1
    Last Post: 29th September 2009, 20:44
  4. QLineEdit padding
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 17th September 2008, 23:43
  5. Replies: 7
    Last Post: 15th November 2007, 18:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.