Question

I had a look for the answer to this but couldn't find anything on here so I'm asking it.

With QStandardModel it is fairly straight forward to get the item from the QModelIndex with the command function itemFromIndex.

model = openedIndex.model()
item = model.itemFromIndex(openedIndex)

I'm interested in doing basically the same but for QFileSystemModel, is there an easy or straight forward way for me to do this. Couldn't see anything in the docs.

Was it helpful?

Solution

QFileSystemModel doesn't have any item class. It doesn't create an object for each item.

You may find QFileSystemModel::filePath and QFileSystemModel::index methods useful. They allow to convert index to path and vice versa. Both index and path can be used as unique item identifier.

Disabling some items in QFileSystemModel is not possible directly. You need to create a proxy model class that will return almost the same data and flags as the source model but remove Qt::ItemIsEnabled flag when needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top