MATLAB Answers

Why isn't the 'ValueChangedFcn' callback called reliably when setting the value of the corresponding UI component to a particular value in the corresponding 'ValueChangingFcn' callback function of that component?

9 views (last 30 days)
Given is an UI component 'app.UIComponent' (such as slider, knob, etc.) for which both callback functions 'ValueChangedFcn' and the 'ValueChangingFcn' are defined.
It is known that callback 'ValueChanged' callback is triggered when the value 'app.UIComponent.Value' of the UIComponent is changed graphically, whereas the callback 'ValueChangingFcn' changes the value 'event.Value' continuously while the slider or pointer are dragged graphically. All callback functions in an App in App designer receive two input variables, 'app' and 'event', where 'app' is the object of the class itself and 'event' is a struct that contains such information as 'event.Value' which is may be changed continuously.
When the value of the UIComponent 'app.UIComponent' is explicitly set to the value 'event.Value' within the callback function 'ValueChangingFcn', then it is noticed that the callback function 'ValueChangedFcn' is not always triggered when the value of the correspoding UIComponent has been changed, namely,
function ValueChangingFcn(app, event)
app.UIComponent.Value = event.Value;
end
Why isn't the 'ValueChangedFcn' callback called reliably when setting the value of the corresponding UI component to a particular value in the corresponding 'ValueChangingFcn' callback function of that component?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 30 Jul 2021
When dragging or turning the slider or pointer of a slider or a knob, respectively, then callback function 'ValueChangingFcn' is being continuously triggered whereas callback function 'ValueChangedFcn' is only called when the slider or knob is released. That in turn means that when the slider or knob is released, both callback functions 'ValueChangingFcn' and 'ValueChangedFcn' may be triggered, as the Callback function 'ValueChangingFcn' evaluates in periodic time instances during the dragging or turning of a slider or pointer of a slider or knob, respectively. However, the callback function 'ValueChangedFcn' will only be called, if the actual value of the UIComponent has been changed.
Now, since the value of the UIComponent is explicitly set within the callback function 'ValueChangingFcn', then callback function 'ValueChangedFcn' won't be triggered, if callback function 'ValueChangingFcn' is triggered. That is the reason why in this case the callback function 'ValueChangedFcn' might not be trigggered.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!