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?
//Only select Root nodes
if ( item->parent())
{
item->setCheckState(0, Qt::Unchecked);
return;
}
//Set state for all leaf nodes
Qt::CheckState state = item->checkState(0);
QList<QTreeWidgetItem*>children = item->takeChildren();
{
child->setCheckState(0, state);
item->addChild(child);
}
//Only select Root nodes
if ( item->parent())
{
item->setCheckState(0, Qt::Unchecked);
return;
}
//Set state for all leaf nodes
Qt::CheckState state = item->checkState(0);
QList<QTreeWidgetItem*>children = item->takeChildren();
foreach(QTreeWidgetItem* child, children)
{
child->setCheckState(0, state);
item->addChild(child);
}
To copy to clipboard, switch view to plain text mode
Bookmarks