1

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.

ceorron
  • 1,230
  • 1
  • 17
  • 28

1 Answers1

2

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.

Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • Then if that is not the case, any ideas how I might go about disabling it's items. If I set filtering the items get disabled so I assume it must be possible? – ceorron Feb 11 '14 at 22:20
  • 1
    It's 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. – Pavel Strakhov Feb 12 '14 at 10:41
  • I have created a proxy model, how would I go about removing the `Qt::ItemIsEnabled` flag using the proxy model. – ceorron Feb 12 '14 at 12:18
  • Pavel Strakhov, you gave me the answer I needed to change ItemIsEnabled to false if you would like to add it as an answer I will mark it as correct. – ceorron Feb 12 '14 at 21:05