Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to totally remove the filtered file from QListView?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 796 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    slumberdin
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        slumberdin
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved