GUI buttondownfnc for mouse clickback does not callback or do anything
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuestas (1)
Geoff Hayes
el 18 de Abr. de 2015
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 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!