Turning HitTest off for imrect

11 views (last 30 days)
Stephen on 15 Jul 2014
Answered: Brian on 16 Jan 2023 at 18:01
I have been trying to turn the HitTest property off for an imrect object, such that I can click on objects behind it. However, a simple "set(imrectHan,'HitTest','off');" does not do the trick. Does anyone know how to solve this?

Accepted Answer

Sean de Wolski
Sean de Wolski on 15 Jul 2014
Edited: Sean de Wolski on 15 Jul 2014
The imrect is built from low-level lines and patches so turn the imrect's Children's 'HitTest' off.
h = imrect
Stephen on 15 Jul 2014
Thank you, that worked very well!

Sign in to comment.

More Answers (2)

Ben11 on 15 Jul 2014
Edited: Ben11 on 15 Jul 2014
What if you inverse the order of Children in your axes? Basically you would send the rectangle at the "back" of the current axis so you could play around with other elements. When you're done you can switch back. It might not be perfect but I think it would work; from the Matlab doc imrect does not have a HitTest property so maybe that's why using it does not work.
Example code to flip the order of the axes children:
Thanks to Matt Fig who provided the idea here
I tried with a simple code and 2 rectangles and it worked well.
Ben11 on 15 Jul 2014
Yep! I learned something with Sean's answer ; I did not know the trick to get the Children of imrect that's nice.

Sign in to comment.

Brian on 16 Jan 2023 at 18:01
NOTE: I created an image in a UIAxes using imagesc:
app.My_image_handle = imagesc(app.UWBAxes, app.UWBdata);
In that case I do NOT set the HitTest property of children of the image handle. Rather I set it directly on the image handle:


Find more on Startup and Shutdown 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!

Translated by