Qt World Summit: Register Today!

QLabel won't expand depending on text content

  • Hi all,

    I am experiencing an issue with a QLabel in a QDialog. I'd like my QLabel to expand depending on the text content.
    This QLabel is in a QHorizontalLayout, itself in a QVerticalLayout.
    Here's how it's designed :


    I have changed the QLabel's sizePolicy to Expanding.
    I have set the layoutSizeConstraint of all the labels to SetMaximumSize.

    But here's how it's displayed :

    text alternatif

    It still won't expand.

    Anyone would have an idea of what I don't see here ?

  • Hi,
    you will have to use FIXED (and not prescribe an actual size) to set the label size according to its contents. Expanding means, every widget with policy EXPANDING gets as much space as allowed by the other widget's policies, maybe more or less than its contents size. If there are two or more widgets with EXPANDING they share the "allowed" space.

Log in to reply