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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.