I have two classes, one based on QTreeView (dirsView) and second on QListView (filesView). dirView has QDirModel with QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks set and filesView with QDir::Files.
When directory is pressed dirsView emits directoryChanged(dirsModel->filePath(index)) and filesView connects this signal to slot with next code:
filesView->setRootIndex(filesModel->index(path));
filesView->setRootIndex(filesModel->index(path));
To copy to clipboard, switch view to plain text mode
Now, when I press on directory in dirsView, filesView shows files, all is OK. Then I press on subdirectory and again on previous directory, filesView shows files and subdirectory. So it shows every subdirectory that was pressed before. To change this I've inserted into slot next code:
filesModel
->setFilter
(QDir::Files);
filesView->setRootIndex(filesModel->index(path));
filesModel->setFilter(QDir::Files);
filesView->setRootIndex(filesModel->index(path));
To copy to clipboard, switch view to plain text mode
But isn't it hack? Is it possible to do it in another way?
Bookmarks