Display in a uicontextmenu the coordinates of clicked point in a uiimage

2 ビュー (過去 30 日間)
Vlad Atanasiu
Vlad Atanasiu 2020 年 10 月 1 日
コメント済み: Vlad Atanasiu 2020 年 12 月 11 日
How do you display in a uicontextmenu the coordinates of the point in a uiimage of a uifigure clicked by the user while opening the context menu? Here is the code template. It shows how you can dynamically change the content of a uicontextmenu, but fails to capture the coordinates of the clicked point. Note that the coordinates of the clicked point are given by the property CurrentPoint of uiaxes and uifigure. The uiaxes information is not available since there are no axes, having created the image with the uiimage function, and the property is zero for uifigure.
function menucoordinates
% display coordinates of clicked point of uiimage in uicontextmenu
% ------------
% Run the function and right-click the image to show the contextual menu
% ------------
fig = uifigure;
% create context menu
cm = uicontextmenu(fig);
cm.ContextMenuOpeningFcn = @onRightClick;
m = uimenu(cm,'Text','');
% create image
im = uiimage(fig);
im.ImageSource = 'membrane.png';
im.ContextMenu = cm;
function onRightClick(src,event)
% update the menu text
% get coordinates of clicked point - HOW?
% ...
% clicked coordinates from uifigure are zero
disp(fig.CurrentPoint)
% dummy values
x = 1;
y = 1;
% display coordinates
m.Text = ['x ',num2str(x),', y ',num2str(y)];
end
end

回答 (1 件)

Abhishek Kumar
Abhishek Kumar 2020 年 12 月 8 日
Hi Vlad, I understand you want to display a point clicked in a uicontextmenu the coordinates of the point in a uiimage, you can refer to the following link:
  3 件のコメント
Abhishek Kumar
Abhishek Kumar 2020 年 12 月 11 日
Hi Vlad, "uiimage" won't make much of a problem the example in the above link is only a reference you can use if with uifigure in similar way:
fig = uifigure;
set(fig,'ButtonDownFcn',@(~,~)disp('uifigure'),...
'HitTest','on')
You can use the handle for image as well with "uiifigure".
Vlad Atanasiu
Vlad Atanasiu 2020 年 12 月 11 日
Dear Abhishek, Your suggestion didn't solve my problem. Maybe you can show how to modify the code in the intial question. Would that be an issue? Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by