Borrar filtros
Borrar filtros

GUI buttondownfnc for mouse clickback does not callback or do anything

3 visualizaciones (últimos 30 días)
Izuru
Izuru el 18 de Abr. de 2015
Respondida: Geoff Hayes el 18 de Abr. de 2015
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 comentarios
Izuru
Izuru el 18 de Abr. de 2015
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 el 18 de Abr. de 2015
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

Iniciar sesión para comentar.

Respuestas (1)

Geoff Hayes
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.

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!

Translated by