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

标签 matlab customization matlab-gui undocumented-behavior matlab-app-designer

我想附加一个 Logo 或更改 App Designer uifigure 的整个背景。如何做到这一点?

最佳答案

  • 如果要为整个图形设置纯色背景,存在a documented way这样做,例如:

    % 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
    

    结果:

    Full-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. 最后两个示例基于以下两个帖子:1 , 2 , 并且操作的原则是添加一个 background-image: "..." 条目到一些所需的 UI 元素的 style 属性(恰好是一个 HTML div).

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

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

关于matlab - 如何自定义 App Designer 图形的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41602238/

相关文章:

java - 在图像处理方面,空间特征和时间特征有什么区别?

matlab - 将向量元胞数组转换为二维矩阵 - MATLAB

r - ESS:ess-request-a-process 默认为 "S"

android:自定义 slider 上的视觉问题

matlab - 在 MATLAB 中单击图像时从指针获取索引值

matlab - 避免使用相同的参数重复调用模拟/函数

c++ - OpenCV SVD 返回与 MATLAB 不同的结果

java - JAXB 构造函数注入(inject)

matlab - 通过单击按钮关闭 uialert 图