fork download
  1. #include <QFileSystemModel>
  2.  
  3. TreeModel_left::TreeModel_left(QObject* parent) : TreeModel(parent) {}
  4. //TreeModel inherits from QFileSystemModel
  5.  
  6. QVariant TreeModel_left::data(const QModelIndex& index, int role) const
  7. {
  8. if (index.column() == 0 && role == Qt::CheckStateRole) {
  9. return checkstatus; //checkstatus is Qt::CheckState
  10. }
  11.  
  12. return QFileSystemModel::data(index, role);
  13. }
  14.  
  15. Qt::ItemFlags TreeModel_left::flags(const QModelIndex& index) const {
  16. if (!index.isValid())
  17. return Qt::NoItemFlags;
  18.  
  19. Qt::ItemFlags flags = QFileSystemModel::flags(index);
  20. if (index.column() == 0) {
  21. flags |= Qt::ItemIsUserCheckable;
  22. }
  23.  
  24. return flags;
  25. }
  26.  
  27. bool TreeModel_left::setData(const QModelIndex& index, const QVariant& value, int role) {
  28.  
  29. if (index.column() == 0 && role == Qt::CheckStateRole) {
  30. Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
  31. checkstatus = state; //checkstatus is Qt::CheckState
  32. }
  33.  
  34. return QFileSystemModel::setData(index, value, role);
  35. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty