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

23 ビュー (過去 30 日間)
Veronica Taurino
Veronica Taurino 2021 年 6 月 21 日
編集済み: Johan C 2021 年 8 月 11 日
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)
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 月 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 日
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
function startupFcn(app)
% Create ContextMenu = uicontextmenu(app.UIFigure);
% Create Menu1 = uimenu(; = 'menu1';
% Create Menu2 = uimenu(; = 'menu2';
function ButtonPushed(app, event)
open( ,event.Source.Position([1 2]))
Best JC


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