View Full Version : Help on adding children to tree view

3rd June 2009, 16:36
I have a TreeView and set it to a SQL model based on QAbstractItemModel.
I want to add child items to a selected item from click event which recalls data from QSqlQueryModel.
I can't find the method to use.
QTreeWidgetItem has a method called addChild() but I don't know how to get the selected item from the treeView.

3rd June 2009, 20:03
Documentation should become your friend. Take a look at QTreeWidget class.
It has

QTreeWidgetItem * currentItem () const

3rd June 2009, 21:03
QSqlQueryModel is a read-only flat model. You won't be able to add children to it. You have to provide your own model or use QTreeWidget instead of QTreeView.

5th June 2009, 08:54
Documentation should become your friend.
there is soooooo much !!

Thanks, I have solved it with wysota's reply (he seems to have all the answers) :(

I read in the docs that removeChild() removes the item but not delete it.
When the node is clicked, any existing child items will need to be removed before refreshing with a new query. Should I recursively delete them as they are removed, like in a for/while loop ?