我还在玩这些uifigure
组件。正如我昨天解释的那样,我有兴趣了解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