GUI buttondownfnc for mouse clickback does not callback or do anything

2 次查看(过去 30 天)
Hi,
I have created an axes to display an image periodically on gui guide called robot_image as the tag.
I want to click on the image and get the coordinates of the mouseclick.
So when I click on my robot_image nothing happens even if I've set the function call as this:
set(handles.robot_image,'ButtonDownFcn',@ImageClickCallback);
I've also set(handles.robot_image, 'HitTest', 'Off');
I'm not sure if it's a problem of my image periodically updating on the axes I can't seem to get the buttondownfcn calling.
  2 个评论
Izuru
Izuru 2015-4-18
I've set the image to be shown on the robot_image axes as:
imageHandle = imshow(image, 'Parent', handles.robot_image);
Not sure if the 'Parent' property somehow affects this....
Izuru
Izuru 2015-4-18
I've done some debugging and it seems that because the image is being updated on the axes periodically, I can't call the buttondownfcn

请先登录,再进行评论。

回答(1 个)

Geoff Hayes
Geoff Hayes 2015-4-18
Izuru - I think that the HitTest should be applied to the image and not the axes (and this will need to occur for each new image that is displayed on the axes), and you need to set the NextPlot property of the axes so that when a new image is added to the axes, the existing set of properties is not cleared (which, as you have identified, is happening when the axes is updated).
In your GUI's OpeningFcn, add the following code
set(handles.robot_image,, 'NextPlot','add');
set(handles.robot_image,'ButtonDownFcn',{@ImageClickCallback,hObject});
Note that we set the NextPlot property to add which adds new graphics objects without clearing or resetting the current axes. In the ButtonDownFcn, we also pass the GUI/figure handle so that we can access the axes from within the ImageClickCallback function as
function ImageClickCallback(hObject, eventdata, hGui)
handles = guidata(hGui);
cursorPoint = get(handles.robot_image, 'CurrentPoint')
See the attached for a simple example that displays a set of images (from the current directory of the GUI) upon pressing the Play button.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by