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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by