PDA

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



weixj2003ld
8th April 2009, 16: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
{
}

aamer4yu
8th April 2009, 19: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 ?

weixj2003ld
9th April 2009, 01: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 )

aamer4yu
9th April 2009, 05: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 :)

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


index.model()->rowCount(index);