Results 1 to 6 of 6

Thread: How to check/uncheck all the items in a QTreeWidget?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question How to check/uncheck all the items in a QTreeWidget?

    Hi,

    I'm using QT Creator to develop an small application. I have a QTreeWidget in the UI and I use the following code to populated:

    Qt Code:
    1. QTreeWidgetItem *mainhh = new QTreeWidgetItem(this->ui->treetables);
    2. mainhh->setText(0, tr("Main Table"));
    3. QStringList lista;
    4. //Move the items to the list
    5. lista << tr("Sub-table 1");
    6. lista << tr("Sub-table 2");
    7. lista << tr("Sub-table 3");
    8. //Many more items ........
    9. //Add the list of subtables as a children of Main Table
    10. new QTreeWidgetItem(mainhh,lista,0);
    11. //Many more parent nodes and childs.......
    12. this->ui->treetables->expandAll(); //Expand the tree
    To copy to clipboard, switch view to plain text mode 

    The code works fine but how can I check/uncheck all the items after I have fulled populated the tree e.g., by clicking a button called "Check/Uncheck all". I guess I need to set some flags and properties to each items with something like:
    Qt Code:
    1. setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
    2. setCheckState(Qt::Unchecked); //or QT::Checked
    To copy to clipboard, switch view to plain text mode 

    But.... I don't know how to go through all the items in the tree to set those properties and flags to each item.

    Many thanks,
    QLands
    Last edited by qlands; 5th March 2010 at 09:39. Reason: Some clarifications

Similar Threads

  1. Checkboxes: check and uncheck
    By 3nc31 in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2008, 21:26
  2. Replies: 5
    Last Post: 6th March 2008, 19:04
  3. QTreeWidget (Row Check, Custom Sort)
    By AaronMK in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2008, 15:55
  4. Check and Uncheck on a Dir Tree?
    By vishal.chauhan in forum Qt Programming
    Replies: 2
    Last Post: 3rd July 2007, 11:55
  5. QListWidgetItem check/uncheck
    By Arthur in forum Qt Programming
    Replies: 6
    Last Post: 12th May 2006, 10:19

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.