How to set an uicontextmenu onto a uipushtool
1 次查看(过去 30 天)
显示 更早的评论
Hi,
is it possible to set a context menu onto a pushtool in a toolbar? What I want is that the uipushtool triggers its action if it is clicked with a main click, but if it is clicked with the secondary mouse click, it should trigger a menu of options.
The uipushtool object seems to have a property for uicontext, but when I try to use it nothing happens.
h = uipushtool;
h.CData = rand(10,10,3);
hcm = uicontextmenu();
uimenu(hcm,'Label','Some text');
set(h,'uicontextmenu',hcm);
Any ideas? Actually I would be happy just to find a way to convince uipushtool to trigger different actions for different clicks.
Daniel
0 个评论
回答(2 个)
Abhiram Bhanuprakash
2015-5-26
Hi Daniel,
I understand that you need a uicontextmenu for a uipushtool. But I don't understand the reason why you need this. Can you let me know why?
Usually the uipushtool is used to create a single push button for which you can assign a single callback for the regular mouse click. It looks like this is why it has an inactive property 'UIContextMenu'. If you see the documentation here , under 'UIContextMenu - Context menu', it says:
"This property has no effect on uipushtools."
So, if you would like to have multiple operations for different clicks, you can do either of the following depending on your requirement:
1. use multiple uipushtools to create multiple buttons and assign each button to a callback.
2. use a uimenu to add a menu bar menu to your UI. You can create submenus as well. Refer to the examples in the doc.
3. use the uicontextmenu on a graphics object (like a line or any other plot, as shown in the example here )
Hope this helps,
Cheers!
Abhiram
另请参阅
类别
在 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!