Receiving mouse clicks in App Designer UIAxes - stops working after imshow

12 views (last 30 days)
The attached app has a UIAxes and a "Load" button.
Initialy, when you mouse-click on the UIAxes, the word "Button!" is printed to the Comand Window.
Then after I press "Load," and select a PNG file to load and display, the mouse-click callback no longer seems to be called.
Any ideas?

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jan 2023
MATLAB considers graphics objects to be layered. The top-most object that is eligible to receive mouse clicks is typically the one that receives the clicks, unless objects have been specifically configured otherwise.
imshow() creates image() objects, and image() objects are eligible for clicking on, so they typically "hide" the underlying axes.
Lack of a configured mouse click callback for an object does not mean that the mouse click is passed to the next object down for eligibility: instead it means that the object is considered to have accepted the mouse clicks and discarded them.
The behaviour can be controlled by HitTest and PickableParts properties; see the link above.
  1 Comment
David Aronstein
David Aronstein on 26 Jan 2023
Thank you for your help! I still had trouble getting this to work by changing settings on the HitTest and PickableParts for the figure objects, but your help let me to underatand that I can set a ButtonDownFcn callback on the image object:
im = imshow(app.img, 'parent', app.Plot);
set(im, 'ButtonDownFcn', @mouse_click);

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!