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

Layout.verticalStretchFactor or Layout.horizontalStretchFactor does not work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9
    • Quick: Layouts
    • None
    • Linux/X11

    Description

      As the official document says, there are two attached properties since Qt 6.5, Layout.verticalStretchFactor and Layout.horizontalStretchFactor, which allow you to specify the vertical and horizontal stretch factor. For example, if the first item has a stretch factor of 1 and the second item has a stretch factor of 2, the first item will aim to get 1/3 of the available space, and the second will aim to get 2/3 of the available space.

      However, I had a try and did not get the expected result. The two items had the same size.

      Examples:
      https://forum.qt.io/post/809232
      https://forum.qt.io/post/825427
      https://stackoverflow.com/q/78968268/630169
      https://stackoverflow.com/a/78972814/630169

      solved by adding preferredWidth like this:

      RowLayout {
          spacing: 0    
      
          Rectangle {
              Layout.fillWidth: true
              Layout.horizontalStretchFactor: 2
              Layout.preferredWidth: parent.width * 2 / 3
              Layout.fillHeight: true
              color: color.neutral
              opacity: 0.7
          }    
      
          Rectangle {
              Layout.fillWidth: true
              Layout.horizontalStretchFactor: 1
              Layout.preferredWidth: parent.width / 3
              Layout.fillHeight: true
              color: color.dialog
          }
      }

      However in this case fillWidth and horizontalStretchFactor are unnecessary. 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            alekseyka Aleksey Kontsevich
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes