App Designer push button callback on push/hold (not native ButtonPushFcn)

19 次查看(过去 30 天)
I have a need for a callback(s) that reacts to when:
1) Button is pushed
2) Button is released
The native ButtonPressFcn only is called when the button is pressed then released. I could not find anything in the community that would help with a callback, so I tried to instantiate a timer that polls the state of the button. However, the button does not have a "Value" property.
Is there another mechanism or callback that I can use to either poll the value of the button or a true button push/hold callback?

回答(3 个)

Pavan Guntha
Pavan Guntha 2021-10-22
Hello Rick,
You could leverage State Button instead of Push Button. When the Push Button is clicked once, the button appears to press and release. When the State Button is clicked, the button remains in the pressed or released state until it is clicked again. Use the “value” variable in the ButtonValueChanged callback of the State Button to know the state of the button an then take an action.
For more details you could have a look the documentation page of State Button.
Hope this helps!
  1 个评论
Rick Policy
Rick Policy 2021-10-22
Thank you for the suggestion Pavan.
However, the statebutton wasn't working for me either. The callback is still not executed until you click and release the button.
My application really needs a mechanism that can detect when the mouse button is pressed and held on the control (button) and also detect when the mouse button is released. If there was a way to querie the value of the mouse click states when it is positioned over top of a button then that would work too.

请先登录,再进行评论。


Quang Vinh Nguyen
Quang Vinh Nguyen 2022-3-27
Hello Mr
I have a same problem, still not solve it
Did you find any solutions?
  1 个评论
Rick Policy
Rick Policy 2022-3-30
We did not find a solution for Matlab App designer.
However, a co-worker was able to get a callback if we port the App Designer code over to the legacy GUIDE. GUIDE allows for push callbacks, and it worked as expected. The downside is Mathworks will someday discontinue support for GUIDE.

请先登录,再进行评论。


Josep Llobet
Josep Llobet 2022-9-22
Hello,
If you want to execute the button, you must execute the 'execution' command of that one. As example, in a app.OriginalButton button:
OriginalButtonValueChanged
Note that when you are writting in the App Designer the button name, it automatically suggest the 'button' statement, in this case OriginalButtonValueChanged, that you can use.
But, if you want to execute an State Button, surely you will need to re-define the state of it previously, it means that first you need to change the value (pushed or not) and then execute it. It is because when you click in State Button, you change the value with the click and then the callback of the button (OriginalButtonValueChanged) is executed. Here what I write in a problem of this style:
if ~app.OriginalButton.Value
app.OriginalButton.Value = true;
app.OriginalButtonValueChanged;
else
app.OriginalButton.Value = false;
app.OriginalButtonValueChanged;
end
Hope this help!

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by