PDA

View Full Version : How to store custom data inside each index in QFileSystemModel



Scope
19th May 2016, 18:03
Hi,

I have QFileSystemModel and I want to store some additional data in each index.
I used setData function like as


model.setData(index, "additional data", Qt::UserRole);

but when I try take these custom data by means of command


qDebug()<< model.index(0, 0, parent).data(Qt::UserRole);

it return invalid QVariant, why? QFileSystemModel does not contain container for custom data? If not then I have to inherit from file system model and store it myself?

For example inside my custom delegate if index represents file I need take size of that file. If index represents folder I want take count of files inside this folder and some more information. How I can this done?

Regards,

anda_skoa
19th May 2016, 18:38
it return invalid QVariant, why? QFileSystemModel does not contain container for custom data?

I doubt that the model can store data, its purpose is to present the file system data in the Qt model interface.



If not then I have to inherit from file system model and store it myself?

That sounds like a valid approach.
Alternatively you could use a QIdentityProxyModel based proxy

Cheers,
_