How to set an uicontextmenu onto a uipushtool

4 ビュー (過去 30 日間)
Daniel
Daniel 2015 年 5 月 23 日
回答済み: Jan 2015 年 6 月 7 日
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

回答 (2 件)

Abhiram Bhanuprakash
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
  1 件のコメント
Daniel
Daniel 2015 年 6 月 7 日
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.

サインインしてコメントする。


Jan
Jan 2015 年 6 月 7 日

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by