Hi,
I need a clickable QML element that is model-based and gives back a reference to its model entry (a complex Object that lives in a QAbstractListModel) on click.
When the Element is generated with a repeater I could use this code (works!):
Repeater {
id: buttonRepeater
model: loaderModel
delegate: CustomButton {
id: customButtonDelegate
objectName: model.name
buttonColor: model.buttonColor
onClicked: { loaderModel.buttonClicked(loaderModel.get(index)) }
}
}
Repeater {
id: buttonRepeater
model: loaderModel
delegate: CustomButton {
id: customButtonDelegate
objectName: model.name
buttonColor: model.buttonColor
onClicked: { loaderModel.buttonClicked(loaderModel.get(index)) }
}
}
To copy to clipboard, switch view to plain text mode
However, within a TableViewColumn this does not work, the latter apparently lacks an "index" (doesn't work!):
TableView {
id: dynamicTableViewBasis
model: sceneLoader.loaderModel
Component {
id: columnComponent
TableViewColumn {
width: 70
delegate: CustomButton {
id: buttonDelegate
objectName: model.nameTop
buttonColor: model.buttonColor
onClicked: {sceneLoader.loaderModel.buttonClicked(sceneLoader.loaderModel.get(index)) }
TableView {
id: dynamicTableViewBasis
model: sceneLoader.loaderModel
Component {
id: columnComponent
TableViewColumn {
width: 70
delegate: CustomButton {
id: buttonDelegate
objectName: model.nameTop
buttonColor: model.buttonColor
onClicked: {sceneLoader.loaderModel.buttonClicked(sceneLoader.loaderModel.get(index)) }
To copy to clipboard, switch view to plain text mode
I recieve an error message that says
ReferenceError: index is not defined
How can I achieve that kind of call (flawlessly working inside a repeater) in a QML TableView?
[Please note that the table's columns are being generated dynamically, thus the "Component" stuff.]
Bookmarks