PDA

View Full Version : QFileSystemModel + UserRole



NIteLordz
14th January 2015, 17:14
so i have been playing with this for an hour or two, and done some googling on it, but am looking for confirmation.

Is it possible to use Qt::UserRole with QFileSystemModel, every time i try to set a value to it, i get a false back, and querying that role for data returns an invalid variant.

Thanks much

d_stranz
14th January 2015, 18:39
I don't think the QFileSystemModel has any built-in support for the Qt::UserRole. The general idea of that role is that it (and roles with higher values - UserRole + 1, etc.) are for your use in custom models. So if you want to store something in model that will be accessed by Qt::UserRole, you will have to derive a model from QFileSystemModel, add data structure support for whatever you want to store, and then implement data() and setData() to return the appropriate QVariant for Qt::UserRole. For all other roles, you can simply call the base class implementation.