我想附加徽标或更改应用程序设计器的整个背景uifigure
。如何才能做到这一点?
-
如果你想设置一个整个图的纯色背景色, 那里存在有记录的方式 https://www.mathworks.com/help/matlab/ref/uifigureappdesigner-properties.html#property_Color为此,例如:
% When creating a new uifigure:
fig = uifigure('Color',[R G B])
% if the uifigure already exists:
fig.Color = [R G B];
- 如果您想更改仅某些区域的背景颜色,您可以添加一个
uipanel
没有标题或边框(uipanel(...,'BorderType','none','Title','','BackgroundColor',[R G B])
).
-
如果你想将图像设置为整个图形的背景:
function q41602238a
%% Turn off some warnings:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
%% 0. Create a uifigure:
app = uifigure();
%% 1. Get a handle to the webwindow:
while true
try
win = struct(struct(app).Controller).Container.CEF;
break
catch
pause(0.1); % Give the figure (webpage) some more time to load
end
end
%% 2. Find the data_tag of the DOM element we want to edit:
data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId);
%% 3. Manipulate the DOM via a JS command
while true
try
win.executeJS(['dojo.style(dojo.query("[data-tag^=''' data_tag ''']")[0],"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
break
catch
pause(0.1); % Maybe JS is still not ready.
end
end
Result:
-
如果你想将图像设置为某个区域的背景:
function q41602238b
%% Turn off some warnings:
warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
%% 0. Create a some element:
app = uifigure();
pnl = uipanel(app);
%% 1. Get a handle to the webwindow:
while true
try
win = struct(struct(app).Controller).Container.CEF;
% disp(win.URL);
break
catch
pause(0.1); % Give the figure (webpage) some more time to load
end
end
%% 2. Find the id of the DOM element we want to edit:
data_tag = char(struct(pnl).Controller.ProxyView.PeerNode.getId);
widgetId = win.executeJS(['dojo.getAttr(dojo.query("[data-tag^=''' data_tag ''']")[0],"widgetid")']);
%% 3. Manipulate the DOM via a JS command
dojo_style_prefix = ['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],'];
while true
try
win.executeJS([dojo_style_prefix '"background-image","url(https://upload.wikimedia.org/wikipedia/commons/8/80/Wikipedia-logo-v2.svg")']);
break
catch
pause(0.1); % Maybe JS is still not ready.
end
end
Result:
Notes:
最后两个例子基于这两篇文章:1 https://stackoverflow.com/a/38933255/3372061, 2 http://undocumentedmatlab.com/blog/customizing-uifigures-part-2,其工作原理是添加一个background-image: "..."
进入到style
某些所需 UI 元素的属性(恰好是 HTMLdiv
).
可以在以下位置找到用于以编程方式操作 App Designer 图形的工具:this https://github.com/StackOverflowMATLABchat/mlapptoolsGitHub 存储库。
示例图像恰好是.svg
,这很有趣,因为我们可以导出“常规的”MATLAB 图形采用这种格式,然后将它们用作背景uifigure
:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)