How do I trigger ButtonDownFcn callback for an object with visible off in MATLAB R2014b?

17 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Oct 2014
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 an invisible object to capture mouse clicks, then set the PickableParts property to 'all'.
For example, create a marker and set the ButtonDownFcn callback so that clicking the marker displays 'hit' at the command line.
m = line(5,5,'Marker','o','MarkerSize',20,'ButtonDownFcn','disp hit');
Set the Visible property of the marker to 'off' to make it invisible.
m.Visible = 'off';
axis([4 6 4 6])
Clicking over the position of the invisible marker does not trigger the ButtonDownFcn callback because invisible objects do not capture clicks by default. Enable the invisible marker to capture clicks by setting the PickableParts property to 'all'.
m.PickableParts = 'all';
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, such as the parent axes.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!