4

I have a tree view displaying a file system model. I want, upon it starting, make a certain file (specifically, current directory) already selected, so that user will not be forced to go all the way down the file system tree to find it. However, neither QTreeView, nor QFileSystemModel don't have any functions to find the item by role and retrieve its QModelIndex.

Septagram
  • 9,425
  • 13
  • 50
  • 81

1 Answers1

8
tree->setCurrentIndex(fsModel->index(QDir::currentPath())); // or any path

Depending on the selection mode the item may or may not be selected.

Hope this helps

zkunov
  • 3,362
  • 1
  • 20
  • 17