ButtonDownFunction on an image in App Designer

25 views (last 30 days)
Hi
I haven't really figured out how to use the 'BottonDownFcn' on an image in the new App Designer.
Here is what I would like to achieve. I click on the top button to load an image, then an image is loaded on the left with a single blue colour (to make things super simple), then I am hoping to apply the buttondown function on this image on the left. How should I do it and where should I put the code, in the top button's callback or somewhere else?
Please can someone give me some advices?

Accepted Answer

Cris LaPierre
Cris LaPierre on 19 Nov 2021
Edited: Cris LaPierre on 19 Nov 2021
Use the axes ButtonDown callback function (added to app designer in R2020b). Rt click on the UIAxes and select 'Callbacks > add UIAxesButtonDown callback function'.
Whatever code you want to execute when you left click on the image goes in this callback function.
There is some setup to get this to work with an image. Namely, you need to set the image object HitTest property to 'off'. There are a number of ways to do this. The default UIAxes callback execution control properties should be set correctly already (worked for me at least).
imagesc(app.ImageAxes,im,"HitTest","off");
% or
im = imread(imgName)
im.HitTest = "off";
In looking into this, I found the following posts helpful.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!