15

I would like to set the height of an element. It should be the height of the highest child element.

Is there something like:

Parent {
    height: max(child1.height, child2.height)
}

Alternatively something like:

Parent {
    height: stretchToChildren
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

33

Math.max() is variadic (taking arbitrarily many arguments).

Depending on actual layout, it might be possible to use Item.childrenRect property.

sergk
  • 3,591
  • 1
  • 20
  • 14
-4
Item {
  width: childrenRect.width // width is now 100
  height: childrenRect.height // height is now 100

  Rectangle {
    width: 100
    height: 100
  }
}

Here is example, how to work childrenRect

freed
  • 129
  • 4