Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何自定义应用程序设计器人物的背景?_Matlab_Customization_Matlab Gui_Undocumented Behavior_Matlab App Designer - Fatal编程技术网

Matlab 如何自定义应用程序设计器人物的背景?

Matlab 如何自定义应用程序设计器人物的背景?,matlab,customization,matlab-gui,undocumented-behavior,matlab-app-designer,Matlab,Customization,Matlab Gui,Undocumented Behavior,Matlab App Designer,我想附加一个徽标或更改应用程序设计器的整个背景uifigure。如何做到这一点? 如果要为整个图形设置一个纯色背景色,可以使用以下方法,例如: % When creating a new uifigure: fig = uifigure('Color',[R G B]) % if the uifigure already exists: fig.Color = [R G B]; 如果只想更改某个区域的背景色,可以添加一个没有标题或边框的uipanel(uipanel(…,'BorderTyp

我想附加一个徽标或更改应用程序设计器的整个背景
uifigure
。如何做到这一点?

  • 如果要为整个图形设置一个纯色背景色,可以使用以下方法,例如:

    % 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
    
    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
    
    结果:

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

    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
    
    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
    
    结果:

笔记:
  • 最后两个示例基于这两篇文章:,其操作原理是将
    背景图像:“…”
    条目添加到某个所需UI元素(恰好是HTML
    div
    )的
    style
    属性中

  • 可以在GitHub存储库中找到一个用于编程操作应用程序设计器图形的工具

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


  • 不幸的是,我还不能发表评论,所以这里是另一个答案

    从Matlab 2017a开始,控制器不再具有容器属性。这项工作:

    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(您可以使用标题或位置进行筛选,但两个相同的UIFigure将导致问题)


    免责声明,Davide Miani在此处发布了该信息:

    app designer
    制作标签也是个好主意。@hbaderts tnx制作标签