PDA

View Full Version : Help on adding children to tree view



vieraci
3rd June 2009, 15: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.

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


QTreeWidgetItem * currentItem () const

wysota
3rd June 2009, 20: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.

vieraci
5th June 2009, 07: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 ?