Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Is there a way to list the full path of an item from QTreeView without using QFileSystemModel?
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).
But how does the data end up in the TreeView/model in first place ?
From the zip i Mean ?
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)
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.
You mean the full path from that set of strings?
yes, i mean what is the full path ?
Is it included in the archive ?
DoubleC122 last edited by DoubleC122
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 ```
JonB last edited by
I think he means (or might mean!): if you've got a treeview with nodes whose "name" is
Tstetc., 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?
@JonB Indeed, but all I have seen online uses QTreeWidgetItem, which needs a QTreeWidget.
JonB last edited by JonB
I know that
QTreeWidgetis built on
QTreeViewbut 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.
ahh, thank you. :)
As far as i know you would have to travel the nodes your self and build it.
Or the model.
view->selectionModel()->selectedIndexes() which might have a first()
@mrjj Yeah, this seems to be working alright. Thanks