detect whether collapsed node has selected child node
-
when a node in my tree view is collapsed, i emit a signal:
void Tree::onNodeCollapsed(const QModelIndex &index) { // get the collapsed node auto pNode = static_cast<TreeNode *>(index.internalPointer()); // execute collapse routine pNode->onCollapsed(); // update the model getTreeModel()->updateModel(); // inform about node collapse in tree view emit nodeCollapsed(pNode); }
later, in a slot:
void SomeObject::onTreeNodeCollapsed(TreeNode *pNode) { if (pNode has a selected child) { // } else { // } }
how can i determine this?
-
Hi
Seems you are using a custom model so just guessing/asking.
Well cant u ask the selected index,
what its parent is and then compare
the parent TreeNode with the pNode ? -
Hi
Seems you are using a custom model so just guessing/asking.
Well cant u ask the selected index,
what its parent is and then compare
the parent TreeNode with the pNode ?@mrjj
ah right. an then do this recursively for the outer levels -
@mrjj
ah right. an then do this recursively for the outer levels@user4592357
Hi
Yes if those are parentless.
If you dont have millions of items in the model, should be fine. -
@user4592357
Hi
Yes if those are parentless.
If you dont have millions of items in the model, should be fine.@mrjj
my bad, i'm noticing only now. my question was not about selected node, but rather a collapsed one. how can i know whether the collapsed node has selected child nodes? -
@mrjj
my bad, i'm noticing only now. my question was not about selected node, but rather a collapsed one. how can i know whether the collapsed node has selected child nodes?@user4592357
Well if the current selected index's parents is the
collapsed node then it has. else not.