Not able to override delegate model, index
-
@Axel-Spoerl, @JonB, @Christian-Ehrlicher
Hi there!I have two files in my simple project,
main.qml, andDelegate.qml:// main.qml import QtQuick import content App { height: 750 width: 375 visible: true ListView { id: lv anchors.fill: parent model: ListModel { ListElement { name: "Hebrew" type: "language" } ListElement { name: "Aramaic" type: "language" } } delegate: Delegate {} } }// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 property var model: ({}) property int index: -1 Text { text: { index + ", " + model.name + ", " + model.type } } }The output I'm getting is this:

However, when I changed myDelegate.qmlas follows:// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 required property var model required property var index Text { text: { index + ", " + model.name + ", " + model.type } } }or even to this:
import QtQuick Rectangle { id: del height: 50 width: 250 Text { text: { index + ", " + model.name + ", " + model.type } } }I get the desired result:

Could you please explain to me why the
modelandindexproperties are not being overridden in the delegate?Is there a way to override them, as I intend to do it here? Please explain.
-
@Axel-Spoerl, @JonB, @Christian-Ehrlicher
Hi there!I have two files in my simple project,
main.qml, andDelegate.qml:// main.qml import QtQuick import content App { height: 750 width: 375 visible: true ListView { id: lv anchors.fill: parent model: ListModel { ListElement { name: "Hebrew" type: "language" } ListElement { name: "Aramaic" type: "language" } } delegate: Delegate {} } }// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 property var model: ({}) property int index: -1 Text { text: { index + ", " + model.name + ", " + model.type } } }The output I'm getting is this:

However, when I changed myDelegate.qmlas follows:// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 required property var model required property var index Text { text: { index + ", " + model.name + ", " + model.type } } }or even to this:
import QtQuick Rectangle { id: del height: 50 width: 250 Text { text: { index + ", " + model.name + ", " + model.type } } }I get the desired result:

Could you please explain to me why the
modelandindexproperties are not being overridden in the delegate?Is there a way to override them, as I intend to do it here? Please explain.
@Ash-V
Maybe I get this wrong, but in the first version, the properties are actually overridden. You can see that at the index being -1.
In the second version, bindings are created and you see the desired output. So in my view, all version behave exactly as expected. -
@Ash-V
Maybe I get this wrong, but in the first version, the properties are actually overridden. You can see that at the index being -1.
In the second version, bindings are created and you see the desired output. So in my view, all version behave exactly as expected.@Axel-Spoerl
Hi Axel!What you've said doesn't seem quite correct, as when I initialized the property
indexwith -5, I got -5 in my output.// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 property var model: ({}) property int index: -5 Text { text: { index + ", " + model.name + ", " + model.type } } }
This simply means that themodelandindexproperties are not being overridden, isn't it?Ping @JonB, @Christian-Ehrlicher
-
@Axel-Spoerl
Hi Axel!What you've said doesn't seem quite correct, as when I initialized the property
indexwith -5, I got -5 in my output.// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 property var model: ({}) property int index: -5 Text { text: { index + ", " + model.name + ", " + model.type } } }
This simply means that themodelandindexproperties are not being overridden, isn't it?Ping @JonB, @Christian-Ehrlicher
-
@Axel-Spoerl
Hi Axel!What you've said doesn't seem quite correct, as when I initialized the property
indexwith -5, I got -5 in my output.// Delegate.qml import QtQuick Rectangle { id: del height: 50 width: 250 property var model: ({}) property int index: -5 Text { text: { index + ", " + model.name + ", " + model.type } } }
This simply means that themodelandindexproperties are not being overridden, isn't it?Ping @JonB, @Christian-Ehrlicher
@Ash-V
Hi,
indexis set to -5,modelis set to {}, which means it's an empty, default constructed model.
Regardless if overridden or not,modelneither has aname, nor atypeproperty.
So I don't quite see the problem here.
Which value would you expect the properties to have?