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

Unexpected width behaviour when using Layout.horizontalStretchFactor

    XMLWordPrintable

Details

    • All
    • c2ae0350a (dev), 819591bea (6.5)

    Description

      I want my two buttons to have the same width. For this I want to use horizontalStretchFactor

      Layout.horizontalStretchFactor: 1 . This makes the button with one character actually bigger than the other.

      No Layout.horizontalStretchFactor

      Is there a way to make the two buttons the same width without doing Layout.preferredWidth: parent.width *.5 ?

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls
      import QtQuick.Controls.Material
      import QtQuick.Layouts
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          RowLayout {
              anchors.fill: parent
              spacing: 0
              Rectangle {
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  color: "orange"
              }
              Rectangle {
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  color: "#ff5733"
              }
          }
      
          RowLayout {
              anchors.fill: parent
              Button {
                  text: "a"
                  Layout.fillWidth: true
                  // Layout.horizontalStretchFactor: 1
                  // Layout.preferredWidth: parent.width * .5
              }
              Button {
                  text: "asdasdasdasdasdasdasd"
                  Layout.fillWidth: true
                  // Layout.horizontalStretchFactor: 1
                  // Layout.preferredWidth: parent.width * .5
              }
          }
      }
      
      

      Attachments

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

        Activity

          People

            smd Jan Arve
            kelteseth Elias Steurer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes