QML如何自动拉伸元素以使其所有子元素适合它?以及如何指定间距?例如,我想在文本周围有一个矩形。矩形应该有一些内部空间。将元素拉伸以包含所有子元素
如果我写下面那么矩形的大小为0,0。
Rectangle {
color: "gray"
anchors.centerIn: parent;
Text {
text: "Hello"
}
}
如果我试图通过使用Column
元素来解决这个问题,如How to make QML items to grow to fit contents?建议的话,我打通了整个窗口/父列,
Column {
anchors.centerIn: parent
Rectangle {
color: "gray"
anchors.fill: parent
}
Text {
anchors.centerIn: parent
text: "Hello"
}
}
编辑:
我也尝试过使用Flow
元素代替Column
,但后来我通过了wh ole窗口/父母。
'main.qml:6:ReferenceError:childrenRect is not defined'。问题是什么? Qt 5.3,QtQuick 2.3 – ManuelSchneid3r 2016-01-02 15:00:44
@ ManuelSchneid3r嗯,我不能重现你的问题。我只是用Qt 5.5来测试它,在将导入改为QtQuick 2.3之后,用'qmlscene'运行上面的代码。工作很好。 – 2016-01-03 15:20:36
问题是我在'Window'scope中试过。在那里,childrenRect没有定义。 – ManuelSchneid3r 2016-01-03 19:55:07