[Solved] How to totally remove the filtered file from QListView?



  • Can someone help me with this kind of problem?

    This is my code snippet:
    @
    void MainWindow::on_pushButton_4_clicked()
    {
    //Filter button
    QString filterType;

    if (ui->comboBox->currentText() == ".txt Plain Text File")
        filterType = "*.txt";
    
    QModelIndex indexFilter = ui->filteredTreeView->currentIndex();
    QStringList filters;
    filters << filterType;
    
    filemodel = new QFileSystemModel(this);
    filemodel->setReadOnly(true);
    filemodel->setRootPath(fsModel->myComputer().toString());
    filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    filemodel->setNameFilters(filters);
    ui->listView->setModel(filemodel);
    ui->listView->setRootIndex(filemodel->setRootPath(indexFilter.data(QFileSystemModel::FilePathRole).toString()));
    

    }
    @

    If I use this code snippet, my filtered file will just be grey-colored as below:

    1-1.docx //in grey color
    1-1.txt //normal color
    1.1.xlsx //in grey color

    What I want to do is,the list view totally remove the .docx and the .xlsx file and will display just .txt file only.
    Does anyone have any idea on how to do it?


  • Lifetime Qt Champion

    Hi,

    call setNameFilterDisables with false on your QFileSystemModel. That will hide the filtered files rather that grey them



  • Thanks SGaist for your help.
    Now,it's working.
    I didn't noticed the function while reading the documentation. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.