Reputation: 1104
I have ListView with some text input fields inside it:
Window {
visible: true
ListModel {
id: textModel
ListElement {
text: "Bill Smith"
}
ListElement {
text: "John Brown"
}
ListElement {
text: "Sam Wise"
}
}
ListView {
width: 180; height: 200
focus: true
model: textModel
delegate: RowLayout{
id: layout
Label {
text: model.text
}
TextField {
text: model.text
}
}
}
}
And I want to set input focus to the first TextField in the list. How can I do this? If I add focus: true
in ListView it does not help.
Upvotes: 2
Views: 638
Reputation: 244252
You have to activate the focus of the TextField using the ListView.isCurrentItem
property:
ListView {
id: view
width: 180; height: 200
focus: true
model: textModel
delegate: RowLayout{
id: layout
Label {
text: model.text
}
TextField {
focus: layout.ListView.isCurrentItem
text: model.text
}
}
// Component.onCompleted: view.currentIndex = 0
}
Upvotes: 2