Clear Filters
Clear Filters

Appdesigner uiaxes data tip context menu

12 views (last 30 days)
Hello,
I have made an app in appdesigner which has a UIAxes with data plotted on it.
When I create a data tip, i am able to right click on the data tip and have a context menu appear.
I would like to modify that context menu to add some menu items that link to callbacks.
Is this possible?

Accepted Answer

Eswaramoorthy
Eswaramoorthy on 1 May 2023
Yes, it is possible to modify the context menu of a data tip in MATLAB App Designer to add menu items that link to callbacks.
Here are the steps you can follow to achieve this:
1. Create a context menu object using the uicontextmenu function.
myContextMenu = uicontextmenu;
2. Add menu items to the context menu object using the uimenu function. Specify the label for the menu item and the callback function that should be executed when the menu item is selected.
menu1 = uimenu(myContextMenu,'Label','Menu Item 1','Callback',@myCallback1);
menu2 = uimenu(myContextMenu,'Label','Menu Item 2','Callback',@myCallback2);
3. Attach the context menu object to the data tip using the set function.
dcm_obj = datacursormode(gcf);
set(dcm_obj,'UiContextMenu',myContextMenu);
4. Define the callback functions that should be executed when the menu items are selected.
function myCallback1(~,~)
disp('Menu Item 1 selected');
end
function myCallback2(~,~)
disp('Menu Item 2 selected');
end
With these steps, you should be able to modify the context menu of the data tip in your MATLAB App Designer app to add menu items that link to callbacks.
Hope this helps!
  1 Comment
John H.
John H. on 1 May 2023
a very thorough and descriptive answer, thankyou!
i will give this a shot in the near future =)

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!