Hi there, I have a QListView that displays pdf files from a Directory. To achieve this, I linked the QListView to the QFileSystemModel. My problem is that I need to be able to search for a file in the QListView using a pattern string, so I employed the use of a QSortFilterProxyModel. The QSortFilterProxyModel works fine except that it doesn't filter when I search for a particular file. Please see my code below.
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6.  
  7. ui->listView_Main->setFlow(QListView::TopToBottom);
  8. ui->listView_Main->setViewMode(QListView::ListMode);
  9. ui->listView_Main->setWrapping(true);
  10. ui->listView_Main->setResizeMode(QListView::Adjust);
  11. ui->listView_Main->setUniformItemSizes(true);
  12.  
  13. QString root_path = "C:/Users/C5248134/Desktop/Projects/build-Ithala-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug/Documents/";
  14.  
  15. proxyModel = new QSortFilterProxyModel(this);
  16.  
  17. f_model = new QFileSystemModel(this);
  18. f_model->setFilter(QDir::Files);
  19.  
  20. proxyModel->setSourceModel(f_model);
  21. proxyModel->setFilterRole(Qt::DisplayRole | Qt::DecorationRole);
  22.  
  23. if(f_model->rootDirectory().exists())
  24. qDebug() << "Dir Found" <<endl;
  25. else
  26. qDebug() << "Dir not found" <<endl;
  27.  
  28. ui->listView_Main->setModel(proxyModel);
  29. ui->listView_Main->setRootIndex(proxyModel->mapFromSource(f_model->setRootPath(root_path)));
  30. }
To copy to clipboard, switch view to plain text mode 

Search button clicked slot.
Qt Code:
  1. void MainWindow::on_btnSearch_clicked()
  2. {
  3. QString patternStr = ui->leSearch->text();
  4. QFileInfoList fileInfoObj = f_model->rootDirectory().entryInfoList();
  5.  
  6. proxyModel->setFilterFixedString(patternStr);
  7. //ui->listView_Main->setRootIndex();
  8. }
To copy to clipboard, switch view to plain text mode 
When I type-in a search string and then click on the search button the entire QListView goes blank. Please see screenshots of how my app looks before and after I search for a file.
Beforescreen2.jpg AfterBlankPic.jpg