我正在尝试将图标放入按钮中,并且正在使用 GUI GUIDE。
在 iconeditor
中,我尝试从 Matlab 图标路径导入文件,但它不起作用。
然后我尝试像这样对按钮进行编程
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)
但它还没有工作。有什么建议吗?
最佳答案
正如我所见,你必须转换它,而你正在这样做......
但是缺少一个参数:
您需要添加工具栏的句柄作为第一个参数:
hpt = uipushtool(ht,'CData',icon,...
在您的情况下,您必须在句柄结构中查找它。如果您不知道如何获取它,请告诉我!
编辑
用于修改工具栏的更多高级功能可以在 Yair 的博客“undocumented Matlab”中找到:
特别是对于您的问题,这可能很有趣:
我强烈推荐 Yair Altman 的博客!!
编辑#2
使用 GUIDE 时,工具栏是自动创建的,并且似乎很难访问其参数。我无法完全测试它,我只是尝试通过以下方式识别工具栏句柄:
hToolbarTogg = findall(gcf,'tag','uitoggletool1');
set(hToolbarTogg,'CData',icon)
你必须找出你的工具栏切换的标签是什么,它应该是相同的,当使用 GUIDE 创建时......
关于matlab - 在 Matlab GUI GUIDE 中更改工具栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18138500/