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. Is there a way to list the full path of an item from QTreeView without using QFileSystemModel?
Forum Updated to NodeBB v4.3 + New Features

Is there a way to list the full path of an item from QTreeView without using QFileSystemModel?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.1k Views 2 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.
  • D Offline
    D Offline
    DoubleC122
    wrote on last edited by
    #1

    Hi, I wanted to know if there was a way to do that, since my items in the QTreeView are not from the filesystem itself (to be precise, they are items from a zip archive).

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

      Hi
      But how does the data end up in the TreeView/model in first place ?
      From the zip i Mean ?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DoubleC122
        wrote on last edited by
        #3

        Oh, I use a libarchive function that returns a set of strings that looks like this:

        Content file: Tst/
        Content file: Tst/Tst/
        Content file: Tst/Tst/24/efaea
        Content file: Tst/Tst/24/efaev
        Content file: Tst/Tst/contents_Test/
        Content file: Tst/Tst/contents_Test/contents_Test.zip.txt
        Content file: Tst/Tst/fff/ef/rgreg.txt
        Content file: Tst/Tst/fff/efafae

        From here I take each string and build a QByteArray that is passed to a TreeModel constructor and then I set that as the model for my QTreeView (there is much more behind but this is just as a quick way to explain what I did)

        mrjjM 1 Reply Last reply
        0
        • D DoubleC122

          Oh, I use a libarchive function that returns a set of strings that looks like this:

          Content file: Tst/
          Content file: Tst/Tst/
          Content file: Tst/Tst/24/efaea
          Content file: Tst/Tst/24/efaev
          Content file: Tst/Tst/contents_Test/
          Content file: Tst/Tst/contents_Test/contents_Test.zip.txt
          Content file: Tst/Tst/fff/ef/rgreg.txt
          Content file: Tst/Tst/fff/efafae

          From here I take each string and build a QByteArray that is passed to a TreeModel constructor and then I set that as the model for my QTreeView (there is much more behind but this is just as a quick way to explain what I did)

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

          @DoubleC122
          ok, but how would u get the full path from that ?
          Im wondering why you simply cant store the extra info in a userRole for the model
          if issues you show one thing, but need full path when clicked.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DoubleC122
            wrote on last edited by
            #5

            You mean the full path from that set of strings?

            mrjjM 1 Reply Last reply
            0
            • D DoubleC122

              You mean the full path from that set of strings?

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

              @DoubleC122
              yes, i mean what is the full path ?
              Is it included in the archive ?

              JonBJ 1 Reply Last reply
              0
              • D Offline
                D Offline
                DoubleC122
                wrote on last edited by DoubleC122
                #7

                Well, to make things a bit more clear, from those strings (using a function I made) I just make a QBitArray that looks like this:

                QBA: 
                Tst
                 Tst
                  24
                   efaea
                   efaev
                  contents_Test
                   contents_Test.zip.txt
                  fff
                   ef
                    rgreg.txt
                   efafae
                

                This is passed in the constructor of a TreeView class (I used the example from http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html). That, based on the blank spaces you see there, files the data to the QTreeView. My actual problem is that I'd need, when clicking on one item, to get the full path, just as I would with QTreeWidget, but QTreeView doesn't seem to have methods like ```
                selectedItems().first().

                1 Reply Last reply
                0
                • mrjjM mrjj

                  @DoubleC122
                  yes, i mean what is the full path ?
                  Is it included in the archive ?

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

                  @mrjj
                  I think he means (or might mean!): if you've got a treeview with nodes whose "name" is Tst etc., and the children with node names as shown, can you get the treeview to "walk" to generate the full "path" to any node by joining the names, like a filing system?

                  D mrjjM 2 Replies Last reply
                  2
                  • JonBJ JonB

                    @mrjj
                    I think he means (or might mean!): if you've got a treeview with nodes whose "name" is Tst etc., and the children with node names as shown, can you get the treeview to "walk" to generate the full "path" to any node by joining the names, like a filing system?

                    D Offline
                    D Offline
                    DoubleC122
                    wrote on last edited by
                    #9

                    @JonB Indeed, but all I have seen online uses QTreeWidgetItem, which needs a QTreeWidget.

                    JonBJ 1 Reply Last reply
                    1
                    • D DoubleC122

                      @JonB Indeed, but all I have seen online uses QTreeWidgetItem, which needs a QTreeWidget.

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

                      @DoubleC122
                      I know that QTreeWidget is built on QTreeView but adds extra levels for convenience, so that may not be suprising. You can always walk the tree to discover the path to a node. But perhaps there is a better/inbuilt way.

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @mrjj
                        I think he means (or might mean!): if you've got a treeview with nodes whose "name" is Tst etc., and the children with node names as shown, can you get the treeview to "walk" to generate the full "path" to any node by joining the names, like a filing system?

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

                        @JonB
                        ahh, thank you. :)
                        As far as i know you would have to travel the nodes your self and build it.
                        Or the model.
                        there is
                        view->selectionModel()->selectedIndexes() which might have a first()

                        D 1 Reply Last reply
                        3
                        • mrjjM mrjj

                          @JonB
                          ahh, thank you. :)
                          As far as i know you would have to travel the nodes your self and build it.
                          Or the model.
                          there is
                          view->selectionModel()->selectedIndexes() which might have a first()

                          D Offline
                          D Offline
                          DoubleC122
                          wrote on last edited by
                          #12

                          @mrjj Yeah, this seems to be working alright. Thanks

                          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