Why is the "ButtonDownFcn" callback for my axes not activated when I click on an object in the axes?

44 ビュー (過去 30 日間)
I have an axes that contains several child objects. I have created a "ButtonDownFcn" callback for the axes. However, when I click on the child objects, the axes' "ButtonDownFcn" callback is not executed.
For example, I create an axis with a line using:
h = line;
set(gca,'ButtonDownFcn','disp(''axis callback'')')
when I click on the axis, I see
axis callback
displayed in the command window. However, if I click on the line, nothing occurs.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
An axes' "ButtonDownFcn" callback is only executed when you click on the axis itself, not the objects in the axis. The "ButtonDownFcn" callback for the child objects will be executed instead.
If you want the axes' "ButtonDownFcn" callback function to be executed regardless of where you click in the axes, try the following:
1. Set the "HitTest" property for the axis' child objects to 'off'. The "HitTest" property determines whether the object can become the current object when it is clicked on. If the "HitTest" property is set to 'off', then the object below it will become the current object, which could be another of the axes' child objects or the axes itself. If all of the axes' child objects have their "HitTest" property set to 'off', then the axes will become the current object and its "ButtonDownFcn" callback will be executed.
set(h,'HitTest','off')
2. Specify the desired callback function as the figure's "WindowButtonDownFcn" property. The "WindowButtonDownFcn" callback is executed whenever you click in the figure, and is executed before the "ButtonDownFcn" callback of any objects, including the figure itself.
set(gcf,'WindowButtonDownFcn','disp(''axis callback'')')
3. Define the "ButtonDownFcn" callbacks for the axes' child objects, so they have the same effect as calling the axes' "ButtonDownFcn" callback. This may include determining the object's Parent (the axes), and passing its handle as an input instead of the object's handle.
set(h,'ButtonDownFcn','disp(''axis callback'')')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by