Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved]Unable to assign fix height to TextArea in ColumnLayout

    QML and Qt Quick
    2
    3
    1250
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      qmlLearner last edited by

      Unfortunately, I am not able to set the height of a TextArea in a ColumnLayout. The property height doesn't seem to have any influence on the displayed height of the TextArea. Code snipped:
      @
      import QtQuick 2.2
      import QtQuick.Controls 1.1
      import QtQuick.Layouts 1.1

      Rectangle {
      id: mainRect
      width: 200
      height: 200

      ColumnLayout {
          id: colLayout
          anchors.fill: parent
      
          Label { text: qsTr("Label") }
      
          TextArea {
              text: "This wants to grow horizontally and should have a fixed height"
              Layout.fillWidth: true
              //Layout.fillHeight: false
              height: 30
              //Layout.height: 40 // => non-existent property "height"
          }
      
          Button {
              text: "Button"
          }
      }
      

      }
      @

      How can I fix this? Do I have to use another property?
      Thank you for any help!

      PS: If I use Column, the height of the TextArea behaves correctly. (But then there is an issue with the width, which is why I would prefer to use ColumnLayout...)

      1 Reply Last reply Reply Quote 0
      • J
        Jens last edited by

        The height property is ignored because the layout will anyway set this for you. (i.e hardcoding the height is not very meaningful in a stretchable layout, since the layout itself will set the height property for you) What you want is to set either the items implicitHeight or more specifically Layout.preferredHeight instead.

        1 Reply Last reply Reply Quote 0
        • Q
          qmlLearner last edited by

          Very nice... Layout.preferredHeight is exactly what I was looking for! Thank you very much!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post