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. Don't show hidden files with QFileSystemModel
Forum Updated to NodeBB v4.3 + New Features

Don't show hidden files with QFileSystemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.9k 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!!

    Is there a way to not show hidden files and folders with a QFileSystemModel?

    I am showing a lot of files that are not necessary and bother.

    Thank you very much!

    jsulmJ 1 Reply Last reply
    0
    • ivanicyI ivanicy

      Hello!!

      Is there a way to not show hidden files and folders with a QFileSystemModel?

      I am showing a lot of files that are not necessary and bother.

      Thank you very much!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ivanicy What about https://doc.qt.io/qt-5/qfilesystemmodel.html#setFilter ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ivanicyI 1 Reply Last reply
      0
      • jsulmJ jsulm

        @ivanicy What about https://doc.qt.io/qt-5/qfilesystemmodel.html#setFilter ?

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        @jsulm Is there a way to hide all files and directories starting with "."? It is that they do not appear as hidden files with the explorer

        jsulmJ 1 Reply Last reply
        0
        • ivanicyI ivanicy

          @jsulm Is there a way to hide all files and directories starting with "."? It is that they do not appear as hidden files with the explorer

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ivanicy Yes, just spend a minute to read the link a gave you then you will also see https://doc.qt.io/qt-5/qdir.html#Filter-enum

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          ivanicyI 1 Reply Last reply
          0
          • jsulmJ jsulm

            @ivanicy Yes, just spend a minute to read the link a gave you then you will also see https://doc.qt.io/qt-5/qdir.html#Filter-enum

            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @jsulm I don't mean the directory . and ..
            I mean, for example, the .cache directory

            jsulmJ 1 Reply Last reply
            0
            • ivanicyI ivanicy

              @jsulm I don't mean the directory . and ..
              I mean, for example, the .cache directory

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ivanicy said in Don't show hidden files with QFileSystemModel:

              .cache

              This is a hidden file/folder on UNIX/Linux, so QDir::Hidden is what you need...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              ivanicyI 1 Reply Last reply
              0
              • jsulmJ jsulm

                @ivanicy said in Don't show hidden files with QFileSystemModel:

                .cache

                This is a hidden file/folder on UNIX/Linux, so QDir::Hidden is what you need...

                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #7

                @jsulm Yeah, in Unix, but in Windows this folder appears like a "normal" folder, not a hidden folder, so I think I have to hide it manually...

                4a99d437-7850-4bf5-9f92-3bcdc95bb3f0-image.png

                JonBJ 1 Reply Last reply
                0
                • ivanicyI ivanicy

                  @jsulm Yeah, in Unix, but in Windows this folder appears like a "normal" folder, not a hidden folder, so I think I have to hide it manually...

                  4a99d437-7850-4bf5-9f92-3bcdc95bb3f0-image.png

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @ivanicy
                  QDir::Hidden means files/directories beginning with . under Linux but with Hidden attribute under Windows. If you are under Windows and a file/directory starts with a . (and does not have Hidden attribute set) you will need to write code to exclude it.

                  Having said that, I do not actually see in QFileSystemModel any facility for you to exclude/filter out file names starting with . under Windows. I don't think the setNameFilters() method will let you achieve that.

                  You might instead achieve the filtering/exclusion for the purpose of not viewing such files/directories by, say, interposing some QAbstractProxyModel between your QFileSystemModel and whatever view you attach, e.g. QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern) or sub-classed bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const, could be used to exclude items starting with a . in their name. I note that e.g. https://stackoverflow.com/questions/11454248/how-to-exclude-dirs-in-qfilesystemmodel says to do just this sort of thing. Similarly the comment in https://stackoverflow.com/a/4927222/489865 points you to https://stackoverflow.com/questions/4893122/filtering-in-qfiledialog which also takes the same approach.

                  1 Reply Last reply
                  2
                  • G Offline
                    G Offline
                    Gukjol
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      Gukjol
                      wrote on last edited by
                      #10

                      What about such option as show hidden files mac?

                      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