How to set an uicontextmenu onto a uipushtool

2 views (last 30 days)
Daniel
Daniel on 23 May 2015
Answered: Jan on 7 Jun 2015
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

Answers (2)

Abhiram Bhanuprakash
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
  1 Comment
Daniel
Daniel on 7 Jun 2015
Hi Abhiram.
Thanks for your answer. Well, I need a contextmenu for the uipushtool because the tool that gets switched on and off with the push can have parameters. For instance, when I click on one of my uipushtools, it changes the functionality of the click. When the tools is on, clicking on the window will create a point. Easy enough. I would like that the user of my code can right-click the uipushtool to change the settings of this tool, as for instance the color of the points that will be created by the tool, or its size, etc. Of course, I could create the uicontextmenu on the objects themselves, but I don't like that. I want to have a contextmenu for the tool itself.

Sign in to comment.


Jan
Jan on 7 Jun 2015

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!