Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ChildrenRect.height always returns 0
Forum Updated to NodeBB v4.3 + New Features

ChildrenRect.height always returns 0

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Felipe.centeno
    wrote on last edited by
    #1

    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
    Flickable{
    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):

    Layouts.FlickableGridLayout{
    ....
    Layouts.GridLayout{
    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!

    E 1 Reply Last reply
    0
    • F Felipe.centeno

      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
      Flickable{
      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):

      Layouts.FlickableGridLayout{
      ....
      Layouts.GridLayout{
      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!

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved