Get and set the active row in QTreeview programmatically (PyQt)

D K picture D K · Sep 18, 2011 · Viewed 8.7k times · Source

Is there a way to get and change the active row in a QTreeView (not QTreeWidget)? By active, I mean the row with the focus highlight, not the selected row. In the paint event, I can use QStyle.State_HasFocus to get the active row, but this doesn't seem to work elsewhere.

Answer

alexisdm picture alexisdm · Sep 18, 2011

You can get/set the active row with the currentIndex() and setCurrentIndex() functions that you can find in both QTreeView and QItemSelectionModel (the latter is returned by QTreeView.selectionModel()).

And despite its name, the QItemSelectionModel handles the view current item, and the view selection independently.