【发布时间】:2011-09-06 22:24:37
【问题描述】:
如何在QML 中自动拉伸元素以使其所有子元素都适合它?以及如何指定间距?例如,我想在文本周围有一个矩形。矩形应该有一些内部间距。
如果我写以下内容,则矩形的大小为 0,0。
Rectangle {
color: "gray"
anchors.centerIn: parent;
Text {
text: "Hello"
}
}
如果我按照 How to make QML items to grow to fit contents? 中的建议尝试使用 Column 元素来修复它,那么我会在整个窗口/父级中获得一列,
Column {
anchors.centerIn: parent
Rectangle {
color: "gray"
anchors.fill: parent
}
Text {
anchors.centerIn: parent
text: "Hello"
}
}
编辑:
我也尝试使用Flow 元素而不是Column,但随后我在整个窗口/父级中得到了一行。
【问题讨论】: