Hi guys,

I'm currently solving almost the same problem, especially the following one:

Quote Originally Posted by jpn View Post
The exclusively checked items should be handled at model side, for example by reimplementing QStandardItem::setData()
I wonder how did you implement the QStandardItem::setData method ? It looks that the only way to do that is
  1. Go through all items in the model and un-check them
  2. Run the default implementation for the being checked item so that the new state is properly processed


So something like this:

Qt Code:
  1. void uncheckBranchItems(QStandardItem * parent_item)
  2. {
  3. for (int i = 0; i < parent_item->rowCount(); ++i)
  4. {
  5. QStandardItem * child_item = parent_item->child(i);
  6. if (Qt::Checked == child_item->checkState())
  7. {
  8. child_item->setCheckState(Qt::Unchecked);
  9. }
  10.  
  11. uncheckBranchItems(child_item);
  12. }
  13. }
  14.  
  15. void RadioButtonItem::setData(const QVariant & value, int role)
  16. {
  17. if (Qt::CheckStateRole == role)
  18. {
  19. if (value.isValid() && (Qt::Checked == static_cast<Qt::CheckState>(value.toInt())))
  20. {
  21. uncheckBranchItems(model()->invisibleRootItem());
  22. }
  23. }
  24.  
  25. QStandardItem::setData(value, role);
  26. }
To copy to clipboard, switch view to plain text mode 

Now imagine that I have another object which subscribes to the QTreeView::clicked() signal, check the item check state and do some custom logic then. I need somehow emulate the signal for the items being un-checked during call to uncheckBranchItems(). The signal should be emitted from the model, not from the item. Because possible subscribers to the signal do not know anything about the items but about model only. How would you do that ?

I'm actually curious what was your implementation of QStandardItem::setData method and whether you implemented some signal notifications on current checked item changes. Probably my solution is bad and you could advise something better where the required signal notifications are easy to do?