Add context menu when LEFT click on button (app design)

조회 수: 8 (최근 30일)
Veronica Taurino
Veronica Taurino 2021년 6월 21일
편집: Johan C 2021년 8월 11일
Hi!
I am trying to add kind of a context menu after LEFT pushing a button on a specific tab of my app, but it seems not to be allowed. Suggestion for a workaround?
I tried uicontextmenu and this link hint (and here) but nothing happens when I push the botton:
function ButtonAddPlotPushed(app, event)
cm = uicontextmenu(app.UIFigure); %
m1 = uimenu(cm,'Text','Menu1');
m2 = uimenu(cm,'Text','Menu2');
m3 = uimenu(cm,'Text','Menu3');
pos = app.ButtonAddPlot.Position(1:2)
set(cm,'Position',pos);
set(cm,'Visible','on');
end
My GUI is something like this:
I need something like this:
I can't use a toolbar instead, because I need it just below the "Output Visualization" tab, while the toolbar is added on the top of the app:
  댓글 수: 3
Veronica Taurino
Veronica Taurino 2021년 6월 21일
I tried a first workaround: I used a dropdown menu and I put a simple image above it. The dropdown works if the user click on the dropdown button area but if the user click on the small image, the dropdown menu does not open. I can't make it open with a callback either
Veronica Taurino
Veronica Taurino 2021년 6월 28일
Is there a way to open the DROP DOWN menu by code? It would be enough to open it when clicking on the image as a callback, but I can't find a way

댓글을 달려면 로그인하십시오.

답변 (2개)

Vimal Rathod
Vimal Rathod 2021년 6월 23일
Hi,
You could try setting up 'HitTest' property of the Image to 'off' that way your UI could register its clicks and hopefully you could call the contextmenu.
Following link contains question similar to yours
  댓글 수: 1
Veronica Taurino
Veronica Taurino 2021년 6월 28일
편집: Veronica Taurino 2021년 6월 29일
Thank you for your answer! How can I implement this solution in the app design? I am not able to find the HIT TEST property on the Inspector or elsewhere, I was looking for something like that. How do I set it?

댓글을 달려면 로그인하십시오.


Johan C
Johan C 2021년 8월 11일
편집: Johan C 2021년 8월 11일
This work for me, hope it helps.
properties (Access = private)
cm % Description
end
function startupFcn(app)
% Create ContextMenu
app.cm.ContextMenu = uicontextmenu(app.UIFigure);
% Create Menu1
app.cm.Menu1 = uimenu(app.cm.ContextMenu);
app.cm.Menu1.Text = 'menu1';
% Create Menu2
app.cm.Menu2 = uimenu(app.cm.ContextMenu);
app.cm.Menu2.Text = 'menu2';
end
function ButtonPushed(app, event)
open(app.cm.ContextMenu ,event.Source.Position([1 2]))
end
Best JC

카테고리

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