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

Layout.verticalStretchFactor or Layout.horizontalStretchFactor does not work

XMLWordPrintable

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

      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. 

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

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

              Created:
              Updated:

                There are no open Gerrit changes