Important: Please read the Qt Code of Conduct -

How to get QLabel border size ?

  • I want to get border size of a QLabel object. I did a research online and found this
    but it was not helpful. and i also wanna know the default border size of QLabel

  • @Ahti
    The default border size of QLabel is platform dependent. What OS are you on?

    What do you want to do with the border size?

  • @Ahti Hi,friend,welcome.

    QLabel inherits QFrame. You should to see QFrame.

    such as,

    int QFrame::frameWidth() const
    int QFrame::lineWidth() const  ///< i think should use this

    try them.

    and default border size of QLabel maybe is 1

  • @Eddy
    Widows 10.
    I am trying to fit the text in the label by keep increasing the height and width of text until it reaches the width and height of label but if border size of label is extended would it come in the way of text which would cause to hide the part of text on the edges ?

  • Hi Ahti,

    Are you using layouts?
    If you do the label will adapt automatically to the needed size of the text in the label. Qt does this for you by changing the sizehint based on the text space needed, you don't need to tinker with those details.

    You can try it out yourself : make a simple QDialog based test application. Put a QLabel in it. Add a layout and make the dialog size minimal by dragging it in Qt Designer. Then hit run.

    Then change the font size to something much bigger and run again. You will see the magic of Qt yourself. The program knows ther is more space needed and the dialog will adapt.

    This is very important when you make versions of your program in other languages. If the translation of your label text is longer. the label will inform it's parent and it will be bigger.

    More information about layouts can be found : in the docs

Log in to reply