簡體   English   中英

MATLAB App Designer 中網格父項中“編輯字段”組件的布局語法

[英]Layout syntax of an Edit Field component in MATLAB App Designer in a grid parent

我想在 MATLAB App Designer 中創建后立即在編輯字段的網格中指定布局。

app.villes1 = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', 'center', ...
              'Editable', 'on', 'Layout', **???**);

我嘗試簡單地使用 [r,c] 但這種語法似乎不正確。 我在谷歌上搜索了我的問題,這是通過創建編輯字段並通過點索引指定行和列來指定行和列的唯一方法:

app.villes1.Layout.Row = 2; 
app.villes1.Layout.Column = i+2; 

但是,我不能使用它,因為我實際上是在 for 循環中生成編輯字段,並且禁止點索引以這種方式:

function initVilles1(app)
    for i=1:8
        app.villes1(i) = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', ...
        'center', 'Editable', 'on');
        app.villes1(i).Layout.Row = 2; 
        app.villes1(i).Layout.Column = i+2; 
     end
end

已經謝謝了! (:

你需要初始化villes1作為陣列gobjects
請參閱圖形數組

例子:

properties (Access = private)
    GHIetPOA_grid  matlab.ui.container.GridLayout
    villes1 = gobjects(1, 8);
end

我只能猜測您使用了以下語法: villes1 = zeros(1, 8);
上面的語法創建了一個double元素數組。
然后app.villes1(i) = uieditfield(...)創建一個“舊式”數字句柄,而不是創建一個對象。
使用數字句柄時禁止點表示法。

您需要使用以下語法: villes1 = gobjects(1, 8); .
現在點索引應該可以工作了。


這是完整的代碼(包括生成的代碼):

classdef app1 < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure  matlab.ui.Figure
    end


    properties (Access = private)
        Panel          matlab.ui.container.Panel
        GHIetPOA_grid  matlab.ui.container.GridLayout
        villes1 = gobjects(1, 8);
    end

    methods (Access = private)

        function initVilles1(app)
            for i=1:8
                app.villes1(i) = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', ...
                'center', 'Editable', 'on');
                app.villes1(i).Layout.Row = 2; 
                app.villes1(i).Layout.Column = i+2; 
             end            
        end
    end


    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            % Create Panel
            app.Panel = uipanel(app.UIFigure);
            app.Panel.Title = 'Panel';
            app.Panel.Position = [42 198 1026 464];

            % Create GridLayout
            app.GHIetPOA_grid = uigridlayout(app.Panel);
            app.GHIetPOA_grid.RowHeight = {'1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x'};

            %app.villes1 = uieditfield(app.GHIetPOA_grid, 'text', 'HorizontalAlignment', 'center', 'Editable', 'on');
            initVilles1(app);
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 1118 692];
            app.UIFigure.Name = 'UI Figure';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = app1

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end

備注:下次發布問題時,請努力發布所有相關代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM