簡體   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