Make an added ListViewItem the currentItem
Solved
QML and Qt Quick
-
Hello guys,
does anyone have an idea how I can easily turn a newly added item to a currentItem in a ListView?
-
-
Thanks, but the new item is not necessarily at the end..
I would need something like that:
ListView { onAdded: { currentIndex = addedIndex } }
-
I tried to use a ScriptAction inside the add Transition:
ListView { id: myList add: Transition { ScriptAction { script: { console.log("add", ViewTransition.index) myList.currentIndex = ViewTransition.index } } } }
But probably for performance reasons the Transition is called only if the new item is visible..
-
The next attempt was to react to the rowInserted signal of the QAIM.
ListView { id: myList model: myModel } Connections { target: myModel function onRowsInserted(parent, first, last) { console.log("inserted", first, last) } }
but the signal is triggered before the list is updated..
-
too early... ListView.onAdd is only called when the new item is visible.
-
use
Qt.callLater
in your rowsInserted signal handler.