문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top