Read of delegate objectName
-
@galilio said in Read of delegate objectName:
ListView{ id: listViewId objectName:"listViewObj" .... delegate: Rectangle { id: rectnagleId objectName: "rectangleDelegate" .... } } //to get item and access the properies function getItemAtIndex(index){ var item = listViewId.itemAtIndex(index); if(item){ console.log(item.objectName) } }
-
@galilio fair enough.
alright, trick 17 (untested)
ListView{ id: listViewId objectName:"listViewObj" var testObject: undefined signal assignToObject(var id) .... delegate: Rectangle { id: rectnagleId objectName: "rectangleDelegate" Connections{ target: listViewId onAssignToObject: if(index === id) listViewId.testObject = rectnagleId } .... } } //to get item and access the properies onTestObjectChanged:{ if(testObject) console.log(testObject.objectName) }
-
@j-hilk said in Read of delegate objectName:
onAssignToObject: if(index === id) listViewId.testObject = rectnagleId
what is your id here
Thanks -
@j-hilk said in Read of delegate objectName:
onAssignToObject: if(index === id) listViewId.testObject = rectnagleId
what is your id here
Thanks@galilio said in Read of delegate objectName:
@j-hilk said in Read of delegate objectName:
onAssignToObject: if(index === id) listViewId.testObject = rectnagleId
what is your id here
Thanksthe argument of the signal
signal assignToObject(var id)
-
@galilio
works fine in my test fileimport QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.0 Window { visible: true width: 400 height: 750 title: qsTr("Hello World") id: root property int testIndex: 0 Timer{ running: true interval: 1000 repeat: true onTriggered: { listViewId.assignToObject(root.testIndex) testIndex++ if(testIndex >= 10) testIndex = 0 } } ListView{ id: listViewId anchors.fill: parent objectName:"listViewObj" property var testObject: undefined onTestObjectChanged:{ if(testObject) console.log(testObject.objectName) } signal assignToObject(var id) model: 10 spacing: 2 delegate: Rectangle { id: rectnagleId objectName: "rectangleDelegate" + index Text { text: modelData anchors.centerIn: parent } width: listViewId.width height: 20 color: "green" Connections{ target: listViewId onAssignToObject: if(index === id) listViewId.testObject = rectnagleId } } } }
-
I want to write a unittest for the QML file.
I could access all objects using ObjectName and check the property.at delegate I can not use objectname and my question how can I access the property within this delegate?
-
Delegate you can't access using the object name. These are dynamically created object.