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.
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!