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. Set Item size based on childrens bounding box

Set Item size based on childrens bounding box

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.6k 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.
  • J Offline
    J Offline
    jimon
    wrote on last edited by
    #1

    simple view :
    @
    import QtQuick 1.0

    Item
    {
    Repeater
    {
    model:
    ListModel
    {
    ListElement {x: 0; y: 50;}
    ListElement {x: 200; y: 200;}
    ListElement {x: 500; y: 3000;}
    ListElement {x: 4000; y: 50;}
    }
    delegate: Rectangle {width: 32; height: 32;}
    }
    }
    @

    application window (and QDeclarativeView widget) frame might be smaller than qml requires, so i setup

    @
    qmlView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    qmlView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    @

    but how can I calculate the root item required size, when I only have it's childrens positions and size ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dajansen
      wrote on last edited by
      #2

      Here's what I tried, and was surprised when it did not work. I'll discuss with the team and report.

      @Item {
      height: 300
      width: 300
      Repeater {
      id: rep
      height: childrenRect.height
      width: childrenRect.width
      onChildrenRectChanged: console.log(childrenRect.height,childrenRect.width)
      model: muhmodel
      delegate: Rectangle { x: model.x; y: model.y; width: 32; height: 32
      color: "brown"; border.color: "black"}
      }
      ListModel {
      id: muhmodel
      ListElement {x: 0; y: 50;}
      ListElement {x: 200; y: 200;}
      ListElement {x: 500; y: 300;}
      ListElement {x: 400; y: 50;}
      }
      }@

      QtQuick Quality Engineer / Lab Monkey
      Nokia Brisbane

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dajansen
        wrote on last edited by
        #3

        The Repeater actually parents the delegates to its own parent - so that it can be layed out with Row/Column etc. So, the parent should be the one using childrenRect.height/width to determine the size. The element should look like:

        @Item {
        height: childrenRect.height
        width: childrenRect.width
        Repeater {
        id: rep
        model: ListModel {
        ListElement {x: 0; y: 50;}
        ListElement {x: 200; y: 200;}
        ListElement {x: 500; y: 300;}
        ListElement {x: 400; y: 50;}
        }
        delegate: Rectangle { x: model.x; y: model.y; width: 32; height: 32
        color: "brown"; border.color: "black"}
        }
        }@

        QtQuick Quality Engineer / Lab Monkey
        Nokia Brisbane

        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