繁体   English   中英

如何自定义App Designer图形的背景?

[英]How to customize the background of an App Designer figure?

我想附上一个徽标或更改App Designer uifigure的整个背景。 如何才能做到这一点?

  • 如果要为整个图形设置纯色背景颜色 ,则存在记录的方法 ,例如:

     % When creating a new uifigure: fig = uifigure('Color',[RGB]) % if the uifigure already exists: fig.Color = [RGB]; 
  • 如果你想改变只是一些区域的背景颜色 ,你可以添加一个uipanel没有标题或边框( uipanel(...,'BorderType','none','Title','','BackgroundColor',[RGB]) )。
  • 如果要将图像设置为整个图形的背景

     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 

    结果:

    全BG

  • 如果要将图像设置为某个区域的背景

     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 

    结果:

    Panel BG

笔记:

  1. 最后两个例子都是基于这两个职位: 12 ,和操作的原理是增加一个background-image: "..."进入到style的一些期望UI元素的属性(这恰好是一个HTML div )。

  2. 可以在 GitHub存储库中找到用于编程操作App Designer图形的工具。

  3. 示例图像碰巧是.svg ,这很有趣,因为我们可以以这种格式导出“常规” MATLAB图形,然后将它们用作uifigure背景:)

不幸的是我还没有评论,所以这是另一个答案。

从Matlab 2017a开始,Controller不再具有Container属性。 这有效:

warning off Matlab:structOnObject
warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame

win = struct(struct(struct(app).Controller).PlatformHost).CEF;

data_tag = char(struct(app).Controller.ProxyView.PeerNode.getId);

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")']);

还可以使用找到所有活动的webwindows

webWindows = matlab.internal.webwindowmanager.instance.findAllWebwindows();

不幸的是我还没有找到,哪个窗口属于哪个UIFigure(你可以使用Title或Position来过滤,但两个相同的UIFigures会导致问题)。

免责声明,Davide Miani在此处发布了这些信息: https//undocumentedmatlab.com/blog/customizing-uifigures-part-1#comment-406524

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM