Hi All

I have a QTreeView with a custom model.
The behaviour I'm looking for is that a user can check or uncheck bottom level items (ie. items that have no children) and when all the siblings have been checked for a particular parent, the parent gets checked.

So far I have no problem with getting the correct bottom level items to check and uncheck but the parent won't update until either it is selected or the QTreeView loses focus.

The reimplemented code for the flags is:

Qt Code:
  1. else if (index.column() == columnHeadingsList.indexOf("Complete"))
  2. {
  3. if ((aNode->children).count() == 0)
  4. {
  5. flags |= Qt::ItemIsUserCheckable;
  6. }
  7. }
To copy to clipboard, switch view to plain text mode 

The code for data is:
Qt Code:
  1. else if (role == Qt::CheckStateRole)
  2. {
  3. if (index.column() == columnHeadingsList.indexOf("Complete"))
  4. {
  5. if (aNode->getIsComplete())
  6. return Qt::Checked;
  7. else
  8. return Qt::Unchecked;
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 

And the code for setData is:
Qt Code:
  1. else if (index.column() == columnHeadingsList.indexOf("Complete"))
  2. {
  3. if (role == Qt::CheckStateRole)
  4. {
  5. // set this node's isComplete
  6. aNode->setIsComplete(value.toBool());
  7.  
  8. // set parent node's isComplete depending on it's children being complete
  9. JBModelRow* aParentNode = aNode->parent;
  10. if (aParentNode)
  11. {
  12. bool aNodeComplete = true;
  13. for (int i = 0; i < (aParentNode->children).count(); i++)
  14. {
  15. if (!aParentNode->children[i]->getIsComplete())
  16. {
  17. aNodeComplete = false;
  18. i = (aParentNode->children).count();
  19. }
  20. }
  21. aParentNode->setIsComplete(aNodeComplete);
  22.  
  23. QModelIndex parentIndex = createIndex(aParentNode->getRow(),
  24. aParentNode->getCol(),
  25. aParentNode);
  26.  
  27. emit dataChanged(parentIndex, parentIndex);
  28. }
  29. }
  30. }
To copy to clipboard, switch view to plain text mode 

Any help appreciated.

Jeff