フィルターのクリア

Why does my uicontextmenu only show after a pause/breakpoint?

2 ビュー (過去 30 日間)
Cyrano Chatziantoniou
Cyrano Chatziantoniou 2023 年 1 月 24 日
回答済み: Jan 2023 年 1 月 24 日
I'm trying to show a contextmenu in a uifigure ontop of some uiaxes. On a mouseclick event, the function below is called to display the contextmenu.
This code runs fine, but when I remove the pause, the contextmenu stops showing. The location also seems to matter, if I put the pause any earlier in the code, no contextmenu shows up. Why is this happening? Are there any race-conditions I should be aware of?
function UOContextMenu(app, id, pos)
%Creates a contextmenu where the user clicked
%Input:
% app - the app
% id - id of the userobject
% pos - cursor position
%Find axis
axID = GUI.FindAxisAtPosition(app, pos);
axis = app.GetAxis(axID);
cm = uicontextmenu(app.UIFigure);
m1 = uimenu(cm,'Text','Delete');
m2 = uimenu(cm,'Text','Rename');
m3 = uimenu(cm,'Text','Copy To');
m4 = uimenu(cm,'Text','Toggle Visibility');
pause(0.1)
cm.Position = [pos(1), pos(2)];
cm.Visible = 'on';
axis.ContextMenu = cm;
return

採用された回答

Jan
Jan 2023 年 1 月 24 日
Try to replace pause by drawnow. This allows the GUI to activate the updated properties. If this is working also, this is the expected and documented behavior. See: drawnow .

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by