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. How to filter folder in treeview
Forum Update on Monday, May 27th 2025

How to filter folder in treeview

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

    http://i.hizliresim.com/LgMq1a.png
    I want to show just Bring2d folder on treeview

    ? 1 Reply Last reply
    0
    • T tako

      http://i.hizliresim.com/LgMq1a.png
      I want to show just Bring2d folder on treeview

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @tako

      The docs are a good place to start: QTreeView Class

          QFileSystemModel *model = new QFileSystemModel;
          model->setRootPath(QDir::currentPath());
          QTreeView *tree = new QTreeView(splitter);
          tree->setModel(model);
      
      T 1 Reply Last reply
      0
      • ? A Former User

        @tako

        The docs are a good place to start: QTreeView Class

            QFileSystemModel *model = new QFileSystemModel;
            model->setRootPath(QDir::currentPath());
            QTreeView *tree = new QTreeView(splitter);
            tree->setModel(model);
        
        T Offline
        T Offline
        tako
        wrote on last edited by
        #3

        @TOMATO_QT please give me example.
        my English is not enough :(

        ? 1 Reply Last reply
        0
        • T tako

          @TOMATO_QT please give me example.
          my English is not enough :(

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @tako

          This the example: model->setRootPath(path-to-directory-you-want-to-display);

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tako
            wrote on last edited by
            #5

            this is not problem. problem is all show folders.
            I want to show I wanted folder

            ? 1 Reply Last reply
            0
            • T tako

              this is not problem. problem is all show folders.
              I want to show I wanted folder

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @tako

              ...show some effort?

              http://stackoverflow.com/questions/12357756/qfilesystemmodel-setrootpath

              T 1 Reply Last reply
              0
              • ? A Former User

                @tako

                ...show some effort?

                http://stackoverflow.com/questions/12357756/qfilesystemmodel-setrootpath

                T Offline
                T Offline
                tako
                wrote on last edited by
                #7

                @TOMATO_QT I could not tell .
                It will only appear in the root directory of your home folder
                so There will not be other folders . (e.g users - bin- etc.) just home folder

                ? 1 Reply Last reply
                0
                • T tako

                  @TOMATO_QT I could not tell .
                  It will only appear in the root directory of your home folder
                  so There will not be other folders . (e.g users - bin- etc.) just home folder

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @tako

                  Perhaps try one of these forums: https://forum.qt.io/category/36/international

                  1 Reply Last reply
                  0
                  • tekojoT Offline
                    tekojoT Offline
                    tekojo
                    wrote on last edited by
                    #9

                    So you want to hide all the other folders?

                    Sounds a lot like:
                    https://forum.qt.io/topic/59973/how-do-i-limit-the-files-that-are-shown-in-qfiledialog

                    Also the file system model docs is a good place to look:
                    http://doc.qt.io/qt-5/qfilesystemmodel.html

                    Hope that helps!

                    1 Reply Last reply
                    0
                    • Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Unfortunately QFileSystemModel does not have a built-in way to filter out directories, only files. The reason is performance related to how file systems work.
                      To do directory filtering you could subclass a QSortFilterProxyModel and implement its filterAcceptsRow() method to pass through only the directory you want.

                      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