Uicontextmenu doesn't work properly when using menu editor in GUI

5 visualizaciones (últimos 30 días)
Matt Markowitz
Matt Markowitz el 19 de Jul. de 2018
Comentada: Matt Markowitz el 20 de Jul. de 2018
I have a GUI with multiple axes, and I want a context menu in one of the axes. I used menu editor to get it to work, but for some reason I can only see the right click options if I don't have an image on the axis. The moment I use imshow on that axis for example, I can no longer see the context menu. I've tried looking around for a solution, but most people seem to be hard coding uicontextmenu, and I want to know how to make it work properly through the menu editor. Thanks for any help.

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Jul. de 2018
In the case where the axes appears to be in the default position as if it is the only axes in the figure, then imshow() deletes the axes and creates a new one. This would, of course, delete anything like context menus that were configured for the axes.
The solution is not to use imshow() for anything other than rough interactive work.
  7 comentarios
Adam
Adam el 20 de Jul. de 2018
Editada: Adam el 20 de Jul. de 2018
imagesc works if you turn the HitTest property of the image off, e.g.
hIm = imagesc( ... )
set( hIm, 'HitTest', 'off' )
This allows the axes, not the image, to pick up mouse events.
However, imshow turns the 'Visible' property of the axes to 'off' which means that even if you include the above line to turn the HitTest of the image off the axes still will not pick up the mouse event because it is invisible. You can switch the axes back on again:
set( handles.axes1, 'Visible', 'on' )
and, together with the image hit test code this should work, though you would need to unshow the axes ticks and labels yourself doing this (this is something I have always done manually so I never realised imshow achieves it by making the axes invisible).
Alternatively, depending on what the general usage of your code is, you could attach the context menu to the image instead of the axes.
Matt Markowitz
Matt Markowitz el 20 de Jul. de 2018
Thank you Adam! This was exactly what I needed.

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks 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