Results 1 to 6 of 6

Thread: Determining QTreeWidget parent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    25
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Determining QTreeWidget parent

    Thanks - that seems a lot more elegant

    R

  2. #2
    Join Date
    Apr 2013
    Location
    North Carolina
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Determining QTreeWidget parent

    Here's some code I use to expand the tree all the way to the root.

    It's a recursive function that accepts a QTreeWidgetItem *item pointer and travels up the tree, starting as position of *item, and expands all parents in the *item's branch until it reaches the *item's topLevelItem.

    Qt Code:
    1. void MyWidget::expandTree(QTreeWidgetItem *item) {
    2. QTreeWidgetItem *parent = item->parent();
    3. if (parent) {
    4. parent->setExpanded(true);
    5. int topLevel = table->indexOfTopLevelItem(parent);
    6. if (topLevel!=-1) {
    7. QTreeWidgetItem *root = table->topLevelItem(topLevel);
    8. root->setExpanded(true);
    9. } else {
    10. if (item->parent()) {
    11. expandTree(item->parent());
    12. }
    13. }
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Determining QTextBlock font
    By smhall316 in forum Newbie
    Replies: 1
    Last Post: 19th October 2010, 22:00
  2. Replies: 5
    Last Post: 21st April 2010, 21:36
  3. Determining no. of CPU cores available
    By cnbp173 in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2009, 17:55
  4. determining how to bounce the ball
    By Binji in forum Qt Programming
    Replies: 9
    Last Post: 29th December 2007, 12:24
  5. Determining Logged In State
    By TheGrimace in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2007, 15:40

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.