How to set the interactivity of uitreenode to 'off'
Ältere Kommentare anzeigen
Question is in the title,
I have a uitree, with top level nodes and children nodes.
I want to disable the interactivity with the children nodes.
When the top level node is checked/unchecked, the children are checked/uncheckd. But the use cannot uncheck/check the children node .
Antworten (2)
Hitesh
am 11 Jun. 2025
Hi Sylvain,
"uitreenode" objects don't have a direct 'Enable' or 'Interactivity' property to disable user interaction with individual nodes like UI controls do. However, you will be able to simulate non-interactivity by using the Checked property and controlling behavior via a callback, essentially preventing user-initiated changes on the child nodes. Kindly follow the below approach to set the interactivity of uitreenode to 'off'.
- Use the CheckedNodesChangedFcn of the uitree.
- Revert any user interaction with the child nodes.
- Allow interaction only through the top-level node.
Refer to following code as an example.
fig = uifigure;
t = uitree(fig, 'checkbox', 'Position', [20 20 200 200]);
% Create top-level node
topNode = uitreenode(t, 'Text', 'Parent Node');
% Create child nodes
child1 = uitreenode(topNode, 'Text', 'Child 1');
child2 = uitreenode(topNode, 'Text', 'Child 2');
% Expand top-level node to show children
expand(topNode);
% Store list of read-only nodes (children)
readOnlyNodes = [child1, child2];
% Set callback to control interaction
t.CheckedNodesChangedFcn = @(src, event) treeCallback(src, event, topNode, readOnlyNodes);
function treeCallback(src, event, topNode, readOnlyNodes)
newChecked = src.CheckedNodes;
if ismember(topNode, newChecked)
% Top node is checked — enforce all children to be checked
src.CheckedNodes = vertcat(topNode, readOnlyNodes(:));
else
% Top node is unchecked — uncheck all
src.CheckedNodes = [];
end
end

For more information regarding "uitreenode", kindly refer to the following MATLAB documentation:
Sylvain
am 12 Jun. 2025
Kategorien
Mehr zu Develop Apps Programmatically finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!