My model is called ContactModel.qml with this code:
import QtQuick 2.2
ListModel {
ListElement {
name: "Jim Williams"
portrait: "item.png"
}
ListElement {
name: "John Brown"
portrait: "item.png"
}
ListElement {
name: "Bill Smyth"
portrait: "item.png"
}
}
and in my main.qml,
GridView
{
width: 1360
height: 1120
cellWidth: width / ((ContactModel.count < 3) ? ContactModel.count: 3)
cellHeight: 386
model: ContactModel {}
delegate: Column
{
Image
{
source: portrait;
anchors.horizontalCenter: parent.horizontalCenter
}
Text
{
text: name;
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
Am I not allowed to use ternary operators/logic in qml files? I would like to have the width, height, and positioning vary depending on the amount of input. When I try to output ContactModel.count, I get nothing via messagebox, text, etc.
↧








