Gridview cellHeight not right unless magic number
-
This is the model, OptionsModel.qml
@import QtQuick 2.2ListModel {
ListElement {
modifier: "Options"
stuff: [
ListElement
{
name: "a"
},
ListElement
{
name: "b"
},
ListElement
{
name: "c"
},
ListElement
{
name: "d"
}
]
}
ListElement {
modifier: "Options"
stuff: [
ListElement
{
name: "a"
},
ListElement
{
name: "b"
},
ListElement
{
name: "c"
},
ListElement
{
name: "d"
}
]
}
}@In my main.qml, I have
@GridView
{
anchors.top: exit.bottom
anchors.left: parent.left
anchors.leftMargin: 20
anchors.right: parent.right
anchors.rightMargin: 20
anchors.bottom: parent.bottom
clip: true
interactive: contentHeight > height
cellWidth: parent.width
cellHeight: deli.height
model: OptionsModel {}
delegate: Rectangle
{
id: deli
height: gob.height + title.height
width: parent.width
anchors.left: parent.left
border.color: "red"
border.width: 1
Text
{
//anchors.fill: parent
id: title
text: modifier
}
Grid
{
id: gob
anchors.top: title.bottom
anchors.left: parent.left
anchors.right: parent.right
columns: 2
spacing: 40
Repeater
{
model: stuff
Rectangle
{
width: 400
height: 84
border.color: "gray"
border.width: 1
color: "transparent"
Text
{
text: deli.height
}
}
}
}
}
}@
I end up with !http://i.imgur.com/MMZRnAZ.png( )!As soon as I change @cellHeight: deli.height@ to @cellHeight: 222@ , I end up with this !http://i.imgur.com/X0RYFMh.png( )!
deli.height is equal to 222. I know this because I set the Text element to display it. Why does changing the GridView's cellHeight to a magic number fix it? The spacing is totally wrong in the first picture(second item of the delegate overlaps with first), but the second one is perfect with zero spacing. -
Ah, GridView does not support variable cellHeights. Solved by making a Repeater nested in a Column nested in a Flickable.