Hi,
If your code example below is right I think you might be wrong on how to use
the list view.
Typically you would set your values in the data model
ListModel {
id: data
ListElement {
value: "value1"
}
ListElement {
value: "value2"
}
ListElement {
value: "value3"
}
}
Setting it to the listView would be the same as you did:
ListView {
id: listView
...
model: data
delegate: rowComponent
} // End of ListView id: listView
But then the delegate would only be one element of the list. The list itself
would generate the elements in the "column".
Component {
id: rowComponent
Text {
id: element
value: model.value
text: model.value
}
=> The ListView will now show three Text-Elements below each other in a List or
"Column". Showing the value. The key is that you bind the value from the model
to the element in the list.
Then the value is already stored in the model which you call data. If you
want to change the value you would directly change it in the model then the
value in the list aka in the delegate will also change.
But I'm not sure if this is the intended use of your program or if you want to
do something special with ListView?
Regards,
Tobias
Date: Fri, 25 Feb 2011 13:04:06 +0100
From: Thomas PABST <[email protected]>
Subject: [Qt-qml] Access to element property
To: "qt-qml.qt.nokia.com" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi,
I'm currently trying to get value from an QML element which is the delegate of
a ListView, but the variable cannot be found.
With the function saveData() I would like to get the value from RowElement
where the id is element1. But qmlViewer return a ReferenceError: Can't find
variable: element1.
Is there a way to get it ?
The following example implement only properties necessary to understand the
problem.
thanks
Item {
id: main
property variant data
function saveData()
{
data.value = element1.value;
...
}
ListView {
id: listView
...
model: data
delegate: rowComponent
} // End of ListView id: listView
Component {
id: rowComponent
Column {
id: topRow
RowElement {
id: element1
value: "value1"
}
RowElement {
id: element2
value: "value2"
}
RowElement {
id: element3
value: "value3"
}
}// End of Column id: topRow
} // End of Component id: rowComponent }
-----------------------------------------------------
Thomas PABST
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110225/a74c395f/attachment.html
------------------------------
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml
End of Qt-qml Digest, Vol 3, Issue 37
*************************************
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml