Set Item size based on childrens bounding box
-
simple view :
@
import QtQuick 1.0Item
{
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 ?
-
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;}
}
}@ -
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"}
}
}@