Qt World Summit: Register Today!

ChildrenRect.height always returns 0

  • I have a Flickable item in where I want to put a customized flow component, so I created the Flickable like this:

    import QtQuick 2.0
    import UICore.Layouts 1.0 as Layouts
    anchors.fill: parent;
    contentWidth: parent.width;
    contentHeight: flow.childrenRect.height;

    Component.onCompleted: {
        console.log("The content height is: " + contentHeight);

    Then in my main.qml I have this (my flickable is Layouts.FlickableGridLayout, and the Layouts.GridLayout is a flow under the hood):

    id: flow
    This works great but the problem is that I want to be able to reuse this item with as little overhead as possible. Setting the id inside of my Layouts.GridLayout doesn't work, and I tried this

    contentHeight: contentItem.childrenRect.height
    as suggested in here under contentWidth section: http://doc.qt.io/qt-5/qml-qtquick-flickable.html#contentItem-prop

    but that always returns 0. I've tried a couple of other ways to receive onCompleted signals but I get the same luck. This doesn't work for example:

    contentHeight: children[0].childrenRect.height
    Which in my mind should be the same as accessing the item through the id, bu apparently not.

    So my question is: how do I get to height of my flow after all the components have been added?

    Thanks in advance!

  • @Felipe.centeno Have you tried to debug the QML code with Creator? Unfortunately you can't easily follow the internals of the engine, like initialization of objects, but you can set a breakpoint into javascript code (onCompleted). You can see the object tree and the properties at that moment.

    If you want to get further help from me you should write a minimal self-contained example showing the problem which I can run, or give all of your code.

Log in to reply