【问题标题】:max/min function in QMLQML 中的最大/最小函数
【发布时间】:2013-08-01 15:48:11
【问题描述】:

我想设置一个元素的高度。它应该是最高子元素的高度。

有没有类似的东西:

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

或者类似:

Parent {
    height: stretchToChildren
}

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    Math.max() 是可变参数(任意多个参数)。

    根据实际布局,可能使用Item.childrenRect 属性。

    【讨论】:

      【解决方案2】:
      Item {
        width: childrenRect.width // width is now 100
        height: childrenRect.height // height is now 100
      
        Rectangle {
          width: 100
          height: 100
        }
      }
      

      这里是示例,如何使用 childrenRect

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-15
        • 2012-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-27
        • 2015-10-29
        相关资源
        最近更新 更多