필터 지우기
필터 지우기

GUI buttondownfnc for mouse clickback does not callback or do anything

조회 수: 3 (최근 30일)
Izuru
Izuru 2015년 4월 18일
답변: Geoff Hayes 2015년 4월 18일
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