PDA

View Full Version : How to add folder contents to qtreeview



mayre
7th February 2014, 12:38
hello I have a question ... how can I pass data from a folder to a treeview ...
all this via a button.
ie I click on the button and I select the items I need window Habré and want those items are displayed in a treeview
thanks in advance ..
God bless you:o

adutzu89
8th February 2014, 09:45
Here is a good example of TreeView (http://qt-project.org/doc/qt-4.8/itemviews-simpletreemodel.html) and here is a tutorial for Model/View (http://qt-project.org/doc/qt-5.0/qtwidgets/modelview.html)

After you know how to create a treeview with folders/files as content, then you can do the following:
Add a button, make a slot where you call the tree view widget whenever the button is clicked.

I am sorry if you are looking for already made code.

Good luck.

Radek
8th February 2014, 11:04
Consider whether you need the QTreeView (a model, abstract and general) or whether you need the QTreeWidget (a ready-to-use tree structure). If you need a QTreeWidget, then:

Adding non-top level item is made at the QTreeWidgetItem level. You need pointers to the parent node and the added item, then do parentNode->AddChild(item) for one item or create QList<QTreeWidgetItem *> from more items added simultaneously and then parentNote->AddChildren(list). Note that the pointers to the added item(s) get owned by the tree and that they need to be created by new. The list itself can be deleted after adding.

Adding top level items is made at QTreeWidget level. Do tree->addTopLevelItem(item) for one item or tree->AddTopLevelItems(list) for a list of items. You can also get the pointer to the invisible root item: root = invisibleRootItem() and add child(ren) as above: root->addChild(item) or root->addChildren(list).