thorpedosg

6CRnZ8sh

Aug 7th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. Parent-dependent QTreeWidgetItem checkboxes in dynamically generated QTreeWidget
  2. connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
  3. this, SLOT(updateChecks(QTreeWidgetItem*, int)));
  4.  
  5. void ClassName::updateChecks(QTreewidgetItem* item, int column)
  6. {
  7. // Checkstate is stored on column 0
  8. if(column != 0)
  9. return;
  10.  
  11. recursiveChecks(item);
  12. }
  13.  
  14. void ClassName::recursiveChecks(QTreeWidgetItem* parent)
  15. {
  16. Qt::CheckState checkState = parent->checkState(0);
  17. for(int i = 0; i < parent->childCount(); ++i)
  18. {
  19. parent->child(i)->setCheckState(0, checkState);
  20. recursiveChecks(parent->child(i));
  21. }
  22.  
  23. }
Add Comment
Please, Sign In to add comment