0

I have a complicated structure of dirs and files, and my goal is to showing files (not all, just files that i need) in one "root" dir, and hide all the rest. I tried work with row count() and data(), but that's gives nothing. index.row() never getting higher, than files quantity in dir. Using QTreeView, Idk, maybe should dig in there

Its like I have this

And need this

1 Answers1

0

Bad english: To do something like this, you need to redefine model methods

QModelIndex parent(const QModelIndex &child) const override // for "virtual" nodes;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override // to get index of "vitrual" nodes";
QModelIndex index(const QString &str, int column = 0) const //to get index of "vitrual" nodes with path;
QString filePath(const QModelIndex &current) const; //to change path of your "vitrual" nodes"
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; //to get data of your "vitrual" nodes"
int rowCount(const QModelIndex &parent = QModelIndex()) const override; //to get as much rows as you need
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; //to check your "vitrual" nodes"
Qt::ItemFlags flags(const QModelIndex &index) const override; //for your "vitrual" nodes" too
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; //need to redefine, or program will crush

and some method, that search/creates data what you need, connected with &QFileSystemModel::directoryLoaded

connect(this, &QFileSystemModel::directoryLoaded, [this](const auto& iPath) {
    QModelIndex index = this->index(iPath);
    if(isDir(index))
        readDirStruct(index);
});

full code implementation is too big, and you can do it "as you see it".