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 show root directory in QFileSystemModel

How to show root directory in QFileSystemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.9k 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.
  • A Offline
    A Offline
    abdullahzubair109
    wrote on last edited by
    #1

    i have a following directory setup... root->childFolder, ChildFile... when i set filesystemmodel for root directory, QTreeView only shows childFolder and childFile, not the root directory itself.. one more thing, i want to hide expansion icon (+) on empty directory.. how could i implement these 2 features??

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

      Hi,

      Can you show the code you are using ?

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

      A 2 Replies Last reply
      0
      • A Offline
        A Offline
        abdullahzubair109
        wrote on last edited by
        #3
        QTreeView *tree = new QTreeView(this);
        QFileSystemModel *model = new QFileSystemModel(this);
        tree->setModel(model);
        model->setRootPath(path);
        tree->setRootIndex(model->index(path));
        

        here path is "/home/home/test1".. there are 3 folders under test1: image, others and pdf. tree view shows them, but i want to show parent directory aka "test1" on top of them. one more thing - 'pdf' folder is empty. but still treeview shows expansion / hide icon (+, -) for it. here is a screenshot 0_1551378119173_Screenshot from 2019-03-01 00-19-20.png

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Can you show the code you are using ?

          A Offline
          A Offline
          abdullahzubair109
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Can you show the code you are using ?

            A Offline
            A Offline
            abdullahzubair109
            wrote on last edited by
            #5

            @SGaist said in How to show root directory in QFileSystemModel:

            Hi,

            Can you show the code you are using ?

            sure

            JonBJ 1 Reply Last reply
            0
            • A abdullahzubair109

              @SGaist said in How to show root directory in QFileSystemModel:

              Hi,

              Can you show the code you are using ?

              sure

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

              @abdullahzubair109
              I've never used this stuff, but is it your setRootIndex() which is wrong?
              https://stackoverflow.com/questions/50357948/difference-between-setrootpath-and-setrootindex-in-qfilesystemmodel

              so the rootIndex() of the model should not be the root that is shown in the view.

              Try playing with it/removing it, see what happens?
              Does it need to be the parent (/home/home) of the root directory (test1) you wish to show in the tree?

              A 1 Reply Last reply
              0
              • JonBJ JonB

                @abdullahzubair109
                I've never used this stuff, but is it your setRootIndex() which is wrong?
                https://stackoverflow.com/questions/50357948/difference-between-setrootpath-and-setrootindex-in-qfilesystemmodel

                so the rootIndex() of the model should not be the root that is shown in the view.

                Try playing with it/removing it, see what happens?
                Does it need to be the parent (/home/home) of the root directory (test1) you wish to show in the tree?

                A Offline
                A Offline
                abdullahzubair109
                wrote on last edited by
                #7

                @JonB in that case all directories under "home/home" will be shown too..I will have to filter out those directories..

                JonBJ 1 Reply Last reply
                0
                • A abdullahzubair109

                  @JonB in that case all directories under "home/home" will be shown too..I will have to filter out those directories..

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

                  @abdullahzubair109
                  Remember I have never used this, but I was thinking:

                  setRootPath("/home/home")
                  setRootIndex("/home/home/test1")
                  

                  ? So perhaps it would be setRootPath() which you would change from what you have now.

                  EDIT I think https://forum.qt.io/topic/7636/qtreeview-root-node-isn-t-shown is what you're looking for?
                  or https://forum.qt.io/topic/67472/qtreeview-shows-all-the-subfolders-but-not-the-parent-folder
                  or https://forum.qt.io/topic/74756/show-root-path-in-qtreeview-for-qfilesystemmodel

                  A 2 Replies Last reply
                  0
                  • JonBJ JonB

                    @abdullahzubair109
                    Remember I have never used this, but I was thinking:

                    setRootPath("/home/home")
                    setRootIndex("/home/home/test1")
                    

                    ? So perhaps it would be setRootPath() which you would change from what you have now.

                    EDIT I think https://forum.qt.io/topic/7636/qtreeview-root-node-isn-t-shown is what you're looking for?
                    or https://forum.qt.io/topic/67472/qtreeview-shows-all-the-subfolders-but-not-the-parent-folder
                    or https://forum.qt.io/topic/74756/show-root-path-in-qtreeview-for-qfilesystemmodel

                    A Offline
                    A Offline
                    abdullahzubair109
                    wrote on last edited by
                    #9

                    @JonB changing setRootPath didn't work...

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @abdullahzubair109
                      Remember I have never used this, but I was thinking:

                      setRootPath("/home/home")
                      setRootIndex("/home/home/test1")
                      

                      ? So perhaps it would be setRootPath() which you would change from what you have now.

                      EDIT I think https://forum.qt.io/topic/7636/qtreeview-root-node-isn-t-shown is what you're looking for?
                      or https://forum.qt.io/topic/67472/qtreeview-shows-all-the-subfolders-but-not-the-parent-folder
                      or https://forum.qt.io/topic/74756/show-root-path-in-qtreeview-for-qfilesystemmodel

                      A Offline
                      A Offline
                      abdullahzubair109
                      wrote on last edited by
                      #10

                      @JonB i will have to use QSortFilterProxyModel 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