QFileDialog, How to hide the hidden files of showing?



  • As we know by default the QFileDialog shows the hidden files.

    ScreenShot

    Is there a way or a method to make the hidden files don't show?


  • Qt Champions 2016

    @Prmego said in QFileDialog, How to hide the hidden files of showing?:

    Hi
    If you are ok with using the Qt and not native dialog, you can use QSortFilterProxyModel
    http://stackoverflow.com/questions/2101100/qfiledialog-filtering-folders

    remember the includes:
    #include <QSortFilterProxyModel>
    #include <QModelIndex>
    #include <QFileSystemModel>



  • Thanks, But I am still at the beginning in use Qt, and that way is a bit difficult.
    is there a short way to do what I want, and what about QFileDialog::setFilter, Is it suitable for that purpose?


  • Qt Champions 2016

    @Prmego said in QFileDialog, How to hide the hidden files of showing?:

    QFileDialog::setFilter

    Yes it should, i must have misread/missed docs as it does have
    QDir::Hidden
    :)
    That is of course much easier.



  • I have written the following code:

    QFileDialog fd;
    fd.setFilter(QDir::Dirs|QDir::Files|QDir::Drives);
    QString openFilePath = fd.getOpenFileName(mainWindow, "Open File", lastDirectoryPath, "Text files (*.txt);;All files (*)");
    

    But unfortunately, when I open the OpenDialog I found it still shows the hidden files/directories.
    I don't know why that happened.


  • Qt Champions 2016

    @Prmego said in QFileDialog, How to hide the hidden files of showing?:

    getOpenFileName

    Try with fd.setOption(QFileDialog::DontUseNativeDialog);



  • I have been appended the setOption as follow:

    QFileDialog fd;
    fd.setFilter(QDir::Dirs|QDir::Files|QDir::Drives);
    fd.setOption(QFileDialog::DontUseNativeDialog);
    QString openFilePath = fd.getOpenFileName(mainWindow, "Open File", lastDirectoryPath, "Text files (*.txt);;All files (*)");
    

    But the hidden files/dirs still shows.


  • Qt Champions 2016

    @Prmego

    Hi try
    QFileDialog fd;
    fd.setFilter(QDir::Dirs|QDir::Files|QDir::Drives);
    fd.setOption(QFileDialog::DontUseNativeDialog);
    fd.exec();

    works with win 10 here.

    I think the reason the other do not work is due to you using a static function.
    Its actually QFileDialog::getOpenFileName(xx)
    so it will ignore ANYTHING u set on fd.

    a static member function is a function that does not need an instance to be be callable.
    Even it seem that its via fd. its not. it has its own inner instance and hence the filter you set
    on the instance fd, does not come into play.



  • Thank you, I appreciate your helping to me.


  • Qt Champions 2016

    @Prmego
    Np. :)
    When not using FileDialog::DontUseNativeDialog it seems to ignore it
    it evens ignore the setting in windows. ( odd enough as its a windows dialog then)


Log in to reply