I have a tree structure shown below implemented within a QTreeWidget

NodeA

->LeafA1

->LeafA2

NodeB

->LeafB1

->LeafB2

The restriction on selection are

Only root nodes are selectable(code snippet below)

Only one root node is selectable - Can readers let me know how this can be done?
Qt Code:
  1. //Only select Root nodes
  2. if ( item->parent())
  3. {
  4. item->setCheckState(0, Qt::Unchecked);
  5. return;
  6. }
  7. //Set state for all leaf nodes
  8. Qt::CheckState state = item->checkState(0);
  9. QList<QTreeWidgetItem*>children = item->takeChildren();
  10. foreach(QTreeWidgetItem* child, children)
  11. {
  12. child->setCheckState(0, state);
  13. item->addChild(child);
  14. }
To copy to clipboard, switch view to plain text mode