Quote Originally Posted by been_1990 View Post
I already can change the checkbox state from checked to unchecked. But that still checks all of them(like you said it would..)
Do you think the code of QStandardItemModel would have the implementation to check/uncheck items independently?
I don’t think the code it has would be very useful, since it relies on instances of QStandardItem to keep the data, and you don’t have a model built on QStandardItems, you have a QFileSystemModel, the backing store of which is not accessible to programs that use the model.

Try something like this (off the top of my head, so errors/typos are not unlikely):
Qt Code:
  1. class CustomModel : public QFileSystemModel {
  2. //...
  3. QSet<QPersistentModelIndex> checklist;
  4. //...
  5. };
  6.  
  7. QVariant CustomModel::data(const QModelIndex& index, int role) const {
  8. if (role == Qt::CheckStateRole) return checklist.contains(index) ? Qt::Checked : Qt::Unchecked;
  9. return QFileSystemModel::data(index, role);
  10. }
  11.  
  12. Qt::ItemFlags CustomModel::flags(const QModelIndex& index) const {
  13. return QFileSystemModel::flags(index) | Qt::ItemIsUserCheckable;
  14. }
  15.  
  16. bool CustomModel::setData(const QModelIndex& index, const QVariant& value, int role) {
  17. if (role == Qt::CheckStateRole) {
  18. if (value == Qt::Checked) checklist.insert(index);
  19. else checklist.remove(index);
  20. emit dataChanged(index, index);
  21. return true;
  22. }
  23. return QFileSystemModel::setData(index, value, role);
  24. }
To copy to clipboard, switch view to plain text mode 

Note that the QSet keeps QPersistentModelIndexes, not ordinary QModelIndexes.