I want my QML code to display a list of strings in text inputs and always have an empty text input at the end of the list. I have this almost working with the following code:
import QtQuick 2.11
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
property var values: ['test1','test2',''];
Column {
id: column
anchors.fill: parent
Repeater {
id: repeater
model: values
Rectangle {
border.width: 1
border.color: "black"
width: column.width
height: childrenRect.height
TextInput {
id: textField
text: qsTr(modelData)
width: column.width
onTextEdited: {
values[index] = textField.text;
if(values[values.length - 1] !== '') {
values.push('');
repeater.model = values;
textField.forceActiveFocus(); //doesn't work
textField.focus = true; //doesn't work
}
}
}
}
}
}
}
The only issue is that when you start typing in the empty TextInput, the app takes focus away from that TextInput after it adds the new empty one to the end of the list. I want the users to be able to smoothly add an entry to the list and then tab to the new empty input and add another one. Setting focus on the TextInput being edited to true and using the forceActiveFocus methods does not seem to work. Is there some other way I can set the focus back after the update?