I have a Qlistview
with some items. I want to set selection at first item at startup of window. selectionModel().selectedRows()
returns the selectet item. But
QAbstractItemModel().setCurrentIndex(0)
does't select the item. How could that be done like setSelection(INDEX)
.
self.listView = QtWidgets.QListView()
self.entry = QtGui.QStandardItemModel()
self.listView.setModel(self.entry)
----------
self.listView.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.listView.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.listView.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
----------
self.listView.QAbstractItemModel().setCurrentIndex(0) #<------ Not really working
selection = self.listView.selectionModel().selectedRows()
print(selection)