我仍在使用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)
相反,如果我从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)
我得到一个空的数字:
在派生类的情况下,谁能解释这种行为和/或知道一种显示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
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