Search code examples
c++qtqfilesystemmodel

Picking selection just for first column (drives, folders, files) of a QFileSystemModel?


In QFileSystemModel when selection is made on it, the return type is a QList<QModelIndex>. Is there a way to get selection just for the first column (the column with drives, folders and files)?


Solution

  • If you are interested in particular selection, you should do next things for every QModelIndex in the list:

    QFileSystemModel* p_fs_model;
    ...
    foreach(QModelIndex index, whole_selection)
    {
      QModelIndex first_column_index = p_fs_model->index(
          index->row(),
          0, /* first column index */
          index->parent()
      );
      ...
    }