MATLAB Answers

0

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

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

Products


Release

R2014b

1 Answer

Answer by MathWorks Support Team on 18 Nov 2016
 Accepted 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.

  0 Comments

Sign in to comment.