我有一个 Flickable 项目,我想在其中放置一个自定义的流组件,所以我创建了这样的 Flickable:
import QtQuick 2.0
import UICore.Layouts 1.0 as Layouts
Flickable{
anchors.fill: parent;
contentWidth: parent.width;
contentHeight: flow.childrenRect.height;
Component.onCompleted: {
console.log("The content height is: " + contentHeight);
}
}
然后在我的 main.qml 中有这个(上面的文件是 MyFlickable,而 MyFlow 是具有特定属性的流):
MyFlickable{
....
MyFlow{
id: flow
...
}
}
这很好用,但问题是我希望能够以尽可能少的开销重用这个项目。在我的 MyFlow 中设置 id 不起作用,我尝试了这个
contentHeight: contentItem.childrenRect.height
正如这里在 contentWidth 部分中所建议的那样:http: //doc.qt.io/qt-5/qml-qtquick-flickable.html#contentItem-prop
但这总是返回 0。我尝试了其他几种方法来接收 onCompleted 信号,但我得到了同样的运气。这不起作用,例如:
contentHeight: children[0].childrenRect.height
在我看来,这应该与通过 id 访问项目相同,但显然不是。
所以我的问题是:在添加了所有组件之后,我如何达到我的流程高度?
提前致谢!