Important: Please read the Qt Code of Conduct -

[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->setFilter(QDir::NoDotAndDotDot | QDir::Files);


    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


    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