Martin Jones wrote:
>> * Can't access the data of the current item in the view from outside the
>> delegate. Inside the implementation of a delegate, it is possible to use
>> model.customDataRole inside the implementation of a delegate, but if in
>> another element you want to get particular data for "the current item
>> selected in that view", it doesn't seem possible in QML.
>
> The current item is available via ListView::currentItem.
The challenge is to access the custom data from a C++ model through its
data() method of the "current" item. Possibly putting the text of the
current item somewhere else in the ui etc. As an example, try to access the
display role of the current item in this QML model:
import Qt 4.7
Rectangle {
height : 400
width : 600
Rectangle {
id : rect
anchors.top : parent.top
anchors.left : parent.left
anchors.right : parent.right
color : "lightsteelblue"
height : 70
MouseArea {
anchors.fill : parent
onClicked :
{
console.log("current item is" + myView.currentItem)
console.log("current item is" + myView.currentItem.data)
console.log("current item is" + myView.currentItem.text)
console.log("current item is" + myView.currentItem.model)
console.log("current item is" + myView.currentItem.display)
console.log("current item is" +
myView.ListView.currentItem.model.display)
}
}
}
ListModel {
id : myModel
ListElement { display : "Red" }
ListElement { display : "Yellow" }
ListElement { display : "Blue" }
}
Component
{
id :myDelegate
Row {
//property alias data : model.display
Text { height : 20; text : "Something" }
Text { height : 20; text : model.display }
}
}
ListView {
id : myView
anchors.top : rect.bottom
anchors.left : parent.left
anchors.right : parent.right
anchors.bottom : parent.bottom
model : myModel
delegate : myDelegate
}
}
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml