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. QFileDialog, How to hide the hidden files of showing?
Forum Updated to NodeBB v4.3 + New Features

QFileDialog, How to hide the hidden files of showing?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 4.6k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Prmego
    wrote on last edited by Prmego
    #1

    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?

    mrjjM 1 Reply Last reply
    0
    • P Prmego

      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?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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>

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Prmego
        wrote on last edited by Prmego
        #3

        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?

        mrjjM 1 Reply Last reply
        0
        • P Prmego

          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?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Prmego
            wrote on last edited by Prmego
            #5

            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.

            mrjjM 1 Reply Last reply
            0
            • P Prmego

              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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              getOpenFileName

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

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Prmego
                wrote on last edited by Prmego
                #7

                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.

                mrjjM 1 Reply Last reply
                0
                • P Prmego

                  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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  @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.

                  1 Reply Last reply
                  1
                  • P Offline
                    P Offline
                    Prmego
                    wrote on last edited by
                    #9

                    Thank you, I appreciate your helping to me.

                    mrjjM 1 Reply Last reply
                    0
                    • P Prmego

                      Thank you, I appreciate your helping to me.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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)

                      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