ButtonDownFcn on Axes after imshow
Show older comments
My ButtonDownFcn for my axes does not work after I call imshow
ax = axes;
set('ButtonDownFcn', @(h,e) disp('Hello'));
imshow(img, 'Parent', ax);
Of course I've read the myriad other post with the same problem and the solution seems to be something like this:
ax = axes;
set('ButtonDownFcn', @(h,e) disp('Hello'));
hold on
h = imshow(img, 'Parent', ax);
set(h, 'HitTest', 'off');
When I do this, it does indeed turn off the hittest for the image, but unfortunately when I click the image I am hitting the figure, not the axes. This is confirmed by the following:
>> hittest()
ans =
Figure (1) with properties:
Number: 1
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [1232 1208 570 450]
Units: 'pixels'hittest()
So how do I force my click to hit the axes and not the figure? My only work around is to set the ButtonDownFcn for the image itself, but this is really not desirable because after some user input I need to overlay (with transparency) a new image which then becomes the top image. I could then set an identical ButtonDownFcn on this new image, but I'm hoping for a better solution than this work around.
Accepted Answer
More Answers (1)
Image Analyst
on 26 Apr 2017
0 votes
Create a callback function and specify that callback function in the callback of the figure, not the axes.
1 Comment
Michael Vaiana
on 27 Apr 2017
Categories
Find more on Interactive Control and Callbacks 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!