How to disable or delete cameratoolbar context menu
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello Matlab community!
Does anyone here know how to disable or delete the cameratoolbar context menu while maintaining the programmatic functionality of the cameratoolbar? I am asking because I am building a GUI that has is own custom context menu which gets broken when the cameratoolbar is enabled. This issue has been flaggegd five years ago in this post, but received no attention from MathWorks.
I am currently using Matlab R2024a.
Here is the screenshot of the context menu I am referring to:

Up to this point, I tried retrieving ContextMenu handles from the cameratoolbar, and the parent UIFigure, and deleting them but this did not work. Any helpful advice on this problem would be greatly appreciated.
Thanks!
댓글 수: 0
답변 (2개)
Adam Danz
2024년 12월 17일
편집: Adam Danz
2024년 12월 17일
This stumped me for a bit but I've found a potential workaround. I'll also make a note of this issue for discussion.
Workaround: When creating the custom context menu, assign its Tag property as CameratoolbarContextMenu.
h.ContextMenu = uicontextmenu(fig,'Tag','CameratoolbarContextMenu');
This will trick cameratoolbar into thinking that it already created its context menu.
Another possibility I found is calling cameratoolbar("SetMode","nomode") after creating the axes toolbar. This removes the cameratoolbar context menu. Then you can reassign the original context menu which is in the figure's children. However, this command will also disable some camera motion controls.
댓글 수: 2
Adam Danz
2024년 12월 17일
Now you know why I called it a potential workaround.
I'm storing my playground code here in case I ever decide to pick this back up. When cameratoolbar is called, the context menu in the first axes is replaced with the cx menu from the second axes which makes sense given how cameratoolbar cleanup works.
fig = uifigure;
tcl = tiledlayout(fig,1,2);
ax1 = nexttile(tcl);
s1 = surf(ax1,peaks);
s1.ContextMenu = uicontextmenu(fig,'tag','CameratoolbarContextMenu');
uimenu(s1.ContextMenu ,'Text','ChangeColor1','MenuSelectedFcn',@(~,~)colormap(ax1,rand(5,3)));
ax2 = nexttile(tcl);
s2 = surf(ax2,peaks);
s2.ContextMenu = uicontextmenu(fig,'tag','CameratoolbarContextMenu');
uimenu(s2.ContextMenu ,'Text','ChangeColor2','MenuSelectedFcn',@(~,~)colormap(ax2,rand(5,3)));
% cameratoolbar
Alex Balan
2025년 1월 7일
Issue:
Camera Toolbar context menu overwrites existing context menus and does not restore them properly.
Cause:
The line 432 in matlab.graphics.internal.CameraToolBarManager in R2024b:
hObj.CurrentObj.UIContextMenu = get(h, 'UIContextMenu');
is problematic because h and hObj.CurrentObj both reference the same object as set on line 420. This makes the line redundant because it is essentially setting the property to its current value.
Suggested Fix:
The correct approach is to store the UIContextMenu of h in hObj.UIContextMenu instead, similar to how it is done on line 422. This allows the code to keep track of the original UIContextMenu of h and restore it later as intended on line 1198.

Proposed Code Change:
Replace:
hObj.CurrentObj.UIContextMenu = get(h, 'UIContextMenu');
with:
hObj.UIContextMenu = get(h, 'UIContextMenu');
This change ensures that the original UIContextMenu is stored separately in hObj, allowing for proper management and restoration of the context menu.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!