View Full Version : how to justfy a node is leaf node or not

8th April 2009, 17:25
In the example simpletreemodel of Qt4.3.1,how to justfy a node is leaf node or not?

view =new QTreeView();
class TreeModel : public QAbstractItemModel
class TreeItem

8th April 2009, 20:10
If the node doesnt have any children, then it is a leaf, isnt it ??
Are you talking in terms of populating the tree, or evaluating from a tree if the node is leaf or not ?

9th April 2009, 02:18
When I double click the tree,I want to justfy the selected node is a leaf one or not.
In the class QModelIndex ,I don't know how to get the child number of QModelIndex ?

void QAbstractItemView::doubleClicked ( const QModelIndex & index )

9th April 2009, 06:19
What are you using ? Model/View or QTreeWidget ?
If you are using model/view you can query QModelIndex::child(0,0)

If it returns a valid QModelIndex, you will know that this has some child. You can be sure because if it has child, firstt will be on row 0, col 0 .

Hope this helps :)

9th April 2009, 08:40
or you can use QAbstractItemModel::rowCount ( const QModelIndex & parent = QModelIndex() ) const which gives you number of rows for which parent is a parent :]