Results 1 to 5 of 5

Thread: how to justfy a node is leaf node or not

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default how to justfy a node is leaf node or not

    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
    {
    }

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to justfy a node is leaf node or not

    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 ?

  3. #3
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to justfy a node is leaf node or not

    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?
    Qt Code:
    1. void QAbstractItemView::doubleClicked ( const QModelIndex & index )
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to justfy a node is leaf node or not

    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

  5. #5
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to justfy a node is leaf node or not

    or you can use QAbstractItemModel::rowCount ( const QModelIndex & parent = QModelIndex() ) const which gives you number of rows for which parent is a parent :]
    Qt Code:
    1. index.model()->rowCount(index);
    To copy to clipboard, switch view to plain text mode 
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.