Reputation: 1132
When using Guide in Matlab to create a GUI with a toolbar, you have the option to use predefined toolbar elements, e.g. open file, zoom in and out... You drag and drop those into your GUI and when you click on one of their icons some auto-generated callback is executed. Is there a way to execute these auto-generated callbacks from your code yourself? I would like to include some of the functionality provided by these toolbar elements within the GUI menu.
Upvotes: 0
Views: 149
Reputation: 65430
You can assign a custom tag to the toolbar item in the "Tool Properties" section. This tag name indicates the field within the handles
struct that contains the handle to the toolbar tool.
You can then get the assigned callback via the ClickedCallback
property, and then execute the callback programmatically using hgfeval
function mycallback(hObject, eventdata, handles)
cback = get(handles.mypushtool, 'ClickedCallback');
hgfeval(cback)
end
If you want to simply copy the callback to your menu, you can modify your OpeningFcn
so that you just copy the ClickedCallback
property of the tool to the menu
function myGUI_OpeningFcn(hObject, eventdata, handles)
set(handles.mymenuitem, 'Callback', get(handles.mytoolbaritem, 'ClickedCallback'));
end
Upvotes: 1