Why does using 'copyobj' function with 'uitreenode' break node selection?

2 visualizzazioni (ultimi 30 giorni)
I am using 'copyobj' function to copy 'uitreenode' within the same 'uitree'. The interactive node selection within a 'uitree' misbehaves when a 'uitreenode' is copied within its parent 'uitree'. When a node is created using 'copyobj' function, the new node and the node it was created from can both be selected, even if the 'Multiselect' property was turned off.
The behavior also persists if a node is copied to a separate 'uitree' and then the new object's parent set to the original.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 15 Apr 2020
Modificato: MathWorks Support Team il 15 Apr 2020
This is a known bug which has been resolved in MATLAB R2018b.
If you are experiencing this issue in MATLAB R2018a or an earlier release, you can use one of the following workarounds:
1. The recommended workaround is to create a custom function to copy 'uitreenodes' as shown below:
function nodeCopy = treeNodeCopyObj(node, parent)
nodeProperties = get(node);
nodeProperties = rmfield(nodeProperties, 'BeingDeleted');
nodeProperties = rmfield(nodeProperties, 'Type');
nodeCopy = uitreenode(parent, nodeProperties);
end
2. Another potential workaround, which is less recommended, is to create a custom 'copyobj' function and put it in your path above the built-in version as shown below:
function nodeCopy = copyobj(node, parent)
if isa(node, 'matlab.ui.container.TreeNode')
nodeProperties = get(node);
nodeProperties = rmfield(nodeProperties, 'BeingDeleted');
nodeProperties = rmfield(nodeProperties, 'Type');
nodeCopy = uitreenode(parent, nodeProperties);
else
builtin('copyobj', node, parent)
end

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by