从matlab.ui.container.GridLayout派生一个类

时间:2019-11-08 13:51:34

标签: matlab matlab-app-designer

我仍在使用uifigure组件。在我explained yesterday的时候,我有兴趣了解matlab.ui.container.GridLayout,最终将其用作某些小部件的基础。

但是当我从matlab.ui.container.GridLayout派生一个类时,我会遇到以下行为,我不理解。我已经在R2019a(Linux)和R2019b(Win)中对此进行了测试:

g = matlab.ui.container.GridLayout('Parent', uifigure()); b = uibutton(g)

enter image description here

相反,如果我从matlab.ui.container.GridLayout派生一个类

classdef MyGrid < matlab.ui.container.GridLayout
    methods
        function self = MyGrid ( varargin )
            self = self@matlab.ui.container.GridLayout( varargin {:} );
        end
    end
end

并使用

g = MyGrid('Parent', uifigure()); b = uibutton(g)

我得到一个空的数字:

enter image description here

在派生类的情况下,谁能解释这种行为和/或知道一种显示Button的方法?

以下是更多信息:

  • 通过在matlab.ui.container.GridLayout.handleChildAdded中设置断点,我发现在将按钮添加到MyGrid实例的情况下会调用此函数
  • 添加按钮后MyGrid的大小会增加:
>> g = MyGrid('Parent', uifigure());
>> g.RowHeight = {};
>> g.ColumnWidth = {}

g = 

  MyGrid with properties:

      RowHeight: {}
    ColumnWidth: {}

  Show all properties

>> b = uibutton(g);
>> g

g = 

  MyGrid with properties:

      RowHeight: {'1x'}
    ColumnWidth: {'1x'}

  Show all properties
  • buttom的Visible属性是on
>> b.Visible

ans =

    'on'
  • 网格的Visible属性也是on
>> g.Visible

ans =

    'on'
  • 按钮的Layout属性正确:
>> b.Layout

ans = 

  GridLayoutOptions with properties:

       Row: 1
    Column: 1
  • Parent属性还可以:
>> f = uifigure();
>> g = MyGrid('Parent', f);
>> b = uibutton(g);
>> b.Parent == g

ans =

  logical

   1

>> g.Parent == f

ans =

  logical

   1

  • Children属性也可以:
>> f.Children(1) == g

ans =

  logical

   1

>> g.Children(1) == b

ans =

  logical

   1

0 个答案:

没有答案