Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Display a QFileSystemModel in two Views: Tree View and a TableView/ListView of selected items



  • Hi,

    I have a TreeView of a QFileSystemModel where I can select files for later use. I store the model indices of these files, and would like to show the selected files in a TableView. How could this be achieved?


  • Lifetime Qt Champion

    Hi,

    You could use a custom QSortFilterProxyModel to filter out the elements not matching your selection.



  • Thanks. I thought about doing this. But I might not understand the QFileSystemModel right yet. If I do

    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override {
        if(source_parent.data(FileSystemModel::IsCheckedRole)==true)
            return true;
        else
            return false;
    }
    

    And display the view as a TreeView nothing is shown, because the root node has IsCheckedRole false. The way I implemented IsCheckedRole is that my model simply contains a list of QModelIndex which stores the items for which IsCheckedRole is true (like this I could avoid walking through the tree). So the problem maybe is, that I have a hierarchical model but would only want a list in my second view.


  • Lifetime Qt Champion

    Why not pass it the selected model indexes from the selection model of your view and filter out everything that's not in that list ?


Log in to reply