How to set an uicontextmenu onto a uipushtool
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Abhiram Bhanuprakash
on 26 May 2015
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
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!