TableView positionViewAtRow
-
Hi
I don't understand how to use the positionViewAtRow function to position a TableView on the last row. The documentation is a bit sparse on the parameters introduced in Qt 6.
No matter what I try, I get a crash.
TableView { id: tableView model: dataModel Component.onCompleted: { let lastRow = dataModel.rowCount - 1; console.log(`lastRow: ${lastRow}`); positionViewAtRow(lastRow, TableView.Contain, 0, Qt.rect(0, 0, 0, 0)) } }
-
Hi
I don't understand how to use the positionViewAtRow function to position a TableView on the last row. The documentation is a bit sparse on the parameters introduced in Qt 6.
No matter what I try, I get a crash.
TableView { id: tableView model: dataModel Component.onCompleted: { let lastRow = dataModel.rowCount - 1; console.log(`lastRow: ${lastRow}`); positionViewAtRow(lastRow, TableView.Contain, 0, Qt.rect(0, 0, 0, 0)) } }
OK, it seems you have to delay the positionViewAtRow call until the model data is loaded.
Timer { id: positionTimer interval: 100 running: false repeat: true onTriggered: { if (dataModel.rowCount > 0) { tableView.positionViewAtRow(dataModel.rowCount - 1, TableView.Contain, 0, Qt.rect(0, 0, 0, 0)); running = false; } } }
And activate it.
TableView { id: tableView model: dataModel Component.onCompleted: positionTimer.running = true }
-
R rincewind has marked this topic as solved on