View Full Version : Accessing data of clicked delegate and inserting it into a Text element (QtQuick/QML)???
Reffyyyy
2011-06-12, 22:42
Essentially, as the title states. I wish to access the text data provided by the selected delegate and insert it into a text field. I have searched but am unable to return any results. I'm using an XMLListModel as the model and ListView to display the data.
Any help would be greatly appreciated.
Thanks
tswindell
2011-06-12, 22:45
Essentially, as the title states. I wish to access the text data provided by the selected delegate and insert it into a text field. I have searched but am unable to return any results. I'm using an XMLListModel as the model and ListView to display the data.
Any help would be greatly appreciated.
Thanks
An example of your source would be of great help y'know ;)
Hi there, I had the same question a few weeks earlier. This is what I did:
// posView is a ListView element
posView.model.get(posView.currentIndex).quoteAsk
Remember, the currentIndex is not automatically updated and you need to assign it manually. For example, in the mouse area to receive the click, you do something like this:
MouseArea {
id: posMouseArea
anchors.fill: background
onClicked: {
posDelegateItem.ListView.view.currentIndex = index
}
}
The 'index' variable comes from Item element that is inherited by ListView.
There are other ways, but this one works for me so I simply use it. I couldn't get the currentItem property in the list view to work, though. You can read this for more info.
http://developer.qt.nokia.com/forums/viewthread/2981
(By the way, I found developer.qt.nokia.com super useful for QT-specific questions.)
In the delegate, in the MouseArea.onClicked, you set the value of a variable outside the delegate.
Text {
id: outsideText
text: "Default text"
}
ListView {
delegate: Item {
MouseArea {
anchors.fill: parent
onClicked: outsideText.text = text
}
}
Reffyyyy
2011-06-12, 22:59
Thanks for all your replies.
@uvatbc
Can't believe I didn't think of that, I'm an idiot. Been a bit of a long day, I guess.
Thanks a lot, guys.
vBulletin® v3.8.8, Copyright ©2000-2025, vBulletin Solutions, Inc.