Question

I'm trying to put an icon in a pushbutton and I'm working with GUI GUIDE.

In iconeditor I try to import a file from Matlab icons path but it doesn't work.

Then I tried to program the button like this

function toolbar_OPT_ClickedCallback(hObject, eventdata, handles)
% hObject    handle to toolbar_Print (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

  % Use a MATLAB icon for the tool
  [X, map] = imread(fullfile(matlabroot,'toolbox','matlab','icons','matlabicon.gif'));

  % Convert indexed image and colormap to truecolor
  icon = ind2rgb(X,map);

  % Create a uipushtool in the toolbar
  hpt = uipushtool('CData',icon)

but its not working yet. Any sugestion?

Was it helpful?

Solution

as I see, you have to convert it and you are doing this...

BUT there is one parameter missing:

you need to add the handle of your toolbar as the first argument:

hpt = uipushtool(ht,'CData',icon,...

In your case you have to look for it within the handles-structure. Let me know, if you dont know how to get this!

EDIT

more advanced features for modifiying toolbars can be found at Yair's Blog "undocumented Matlab":

figure-toolbar-components

Especially for your question, this could be interesting:

figure-toolbar-customizations

I can strongly recommend Yair Altman's Blog!!

EDIT#2

when using GUIDE, your toolbar is created automatically and it seems to be difficult to get acces to its parameters. I couldnt test it completely, I just tried to identify the toolbar-handle by this:

hToolbarTogg = findall(gcf,'tag','uitoggletool1');
set(hToolbarTogg,'CData',icon)

You have to find out the what's the tag of your toolbar-toggle, which should be the same, when created with GUIDE...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top