Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91451

Wrong sizeHint for layout containing a word-wrapped label

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.6, 5.15.0, 6.0.1
    • Widgets: Layout
    • None
    • All

    Description

      When adding a word-wrapped label in a layout, the sizeHint is wrong. In attachment a minimal example is provided. Next to that a screenshot is provided of how it looks on Qt 6.0.1 in combination with macOS 10.15.

      The way a label is word wrapped depends on the font, fontSize, ... So to reproduce this issue on another platform it might be necessary to make the text of the label a bit longer or shorter. It's easiest to reproduce if it's just too long to fit on 2 lines (so only a few characters have to go on a 3rd line)

      I debugged the problem a bit and it looks strange to me that inside QLayout::totalSizeHint(), the heightForWidth is asked for a width that includes the margins of the parentWidget while the layout can not use these margins to place the label.

      Changing

       s.setHeight(heightForWidth(s.width() + side));

      into

       s.setHeight(heightForWidth(s.width()));

      seems to fix the problem for me.

      Attachments

        1. Qt 6.0.1.png
          Qt 6.0.1.png
          37 kB
        2. WordWrap.zip
          3 kB

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            dbutijn David Butijn
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: