Delegate y property change
Hi there,
I have a rectangle on which I want to put some elements positioned along x and y. To do this, I used a model in C++ and a ListView in QML. The delegate has a bind on x and y properties referring to a data of the model through a C++ conversion function. This works fine on x property but not on y property.
I put a trace into onXchanged and onYchanged. X contains the correct value. Y gets the correct value then there's a second trace (this does not happen on x) indicating that y is 0 while the conversion function is called only once.
Any idea?
Thanks
Qt4.8.5, QtQuick 1.1
Re: Delegate y property change
You should give more information (code!). Is the rectangle inside any Layout?
Re: Delegate y property change
It might be easier to use a Repeater. Here is a working example that uses an array as a model (but you can replace it with a C++ model).
Code:
Item {
id: root
width: 1000; height: 600
property var model: [
{"x": 100, "y": 50, "color": "red"},
{"x": 60, "y": 320, "color": "blue"},
{"x": 360, "y": 210, "color": "green"}
]
Rectangle {
color: "gray"
width: 600
height: 400
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
Repeater {
model: root.model
Item {
x: modelData.x
y: modelData.y
Rectangle {
width: 40; height: width; radius: width/2
color: modelData.color
anchors.centerIn: parent
border.color: Qt.darker(color)
border.width: 1
}
}
}
}
}
Re: Delegate y property change
Thanks for your replies,
My project has been postponed, I keep in mind your solution and try it as soon as I can.
Many thanks