MATLAB: How to click an object below another object in MATLAB R2014b

MATLABr2014bgraphics

How do I click an object below another object in MATLAB R2014b?

Best Answer

Starting in MATLAB R2014b, graphics objects have a new PickableParts property that controls if the object can capture mouse clicks. By default, the PickableParts property is set to 'visible' so the object can capture mouse clicks when the Visible property is set to 'on'. If you want to click an object below another object, then set the PickableParts property of the top object to 'none' so that the click passes through it. 
For example, create a red marker and a blue marker. Set the ButtonDownFcn callbacks so that clicking the red marker displays 'red' at the command line, and clicking the blue marker displays 'blue'. Since the blue marker is created second, it appears on top of the red marker. 
mred = plot(5,5,'ro','MarkerSize',15,'ButtonDownFcn','disp red');
hold on
mblue = plot(5,5,'bo','MarkerSize',25,'ButtonDownFcn','disp blue');
Clicking the markers displays 'blue' at the command line. If you want the click to pass through the blue marker to the red marker, then set the PickableParts property of the blue marker to 'none' so that it cannot capture mouse clicks. 
mblue.PickableParts = 'none';
Note: When an object captures a mouse click, the HitTest property controls if the object responds to the click or if it passes the click to an ancestor.  By default, the object responds. Set the HitTest to 'off' if you want an ancestor to respond.