Results 1 to 11 of 11

Thread: Simple way to expand all nodes on a QTreeView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: Simple way to expand all nodes on a QTreeView?

    Hehe, thinking the same thing at the same time . However I must admit you put it more concise, and with the correct references.

    QTreeView::itemsExpandable [as referred to in the feature rejection] does not help in this issue, as it can only be used to prevent the default collapsed item to be expanded...

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: Simple way to expand all nodes on a QTreeView?

    Qt 4.2 introduced QTreeView::expandAll(). Ain't that neat? And the feature reject mentions it BTW...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: Simple way to expand all nodes on a QTreeView?

    Quote Originally Posted by fullmetalcoder View Post
    Qt 4.2 introduced QTreeView::expandAll(). Ain't that neat? And the feature reject mentions it BTW...
    The point is that it's very expensive to call it for large models.
    Warning: if the model contains a large number of items, this function will be take time to execute.
    Now, consider a dynamically changing large model. You don't want to call QTreeView::expandAll() again and again, do you?
    J-P Nurmi

  4. #4
    Join Date
    May 2011
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2

    Default Re: Simple way to expand all nodes on a QTreeView?

    Qt Code:
    1. void MainWindow::expandNode(const QModelIndex &parentIndex, bool expand) {
    2. tree->setExpanded(parentIndex, expand);
    3. for (qint32 rowNum = 0; rowNum < treeModel->rowCount(parentIndex); ++rowNum) {
    4. QModelIndex childIndex = treeModel->index(rowNum, 0, parentIndex);
    5. tree->setExpanded(childIndex, expand);
    6. expandNode(childIndex);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 28th February 2007, 08:34
  2. [QT4] QTreeView and expandable nodes
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2006, 16:52

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
  •  
Qt is a trademark of The Qt Company.