seting default property values for uifigure graphics

4 次查看(过去 30 天)
I would like to set default properties for some uifigure base graphics such as uilabel, uitextfield etc.
The documentation suggests this should work. It worked in many yerars with figure based graphics. When I try setting defaults for uifigure base graphics I get the same error message testing different defaults! - see statement below below.
Is there a simple solution. - I would like to start using uibased graphics. However, I like using defaults (and sometimes I like changing the factory settings).
Morten
set(groot, 'defaultuipanelhorizontalalignment', 'right') % setting 'Default for horizontalalignment in an uicontrol
Error using matlab.ui.Root/set
Unrecognized property Horizontalalignment for class Panel.

回答(1 个)

Walter Roberson
Walter Roberson 2023-2-27
You need to set against ['default' classname PropertyName] and it must be a property that exists in the class.
You cannot say, for example, that within uipanel that the default font should be whatever, because uipanel do not have a font property.
What you can do is set a default against a particular object instead of against groot. You can set the default uipanel createfcn for groot, to be a function that takes the handle of a uipanel being created and applies a default against the object. For example
set(src, 'defaultTextHorizontalAlignment', 'center')
  3 个评论
Walter Roberson
Walter Roberson 2023-2-27
You can set a default property against groot, in which case it applies for all further graphics objects of the appropriate type that are created, unless the property has been overriden by a more specific default setting or by specific properties at individual graphics object construction time.
You can set a default property against a particular container object (such as a figure or uipanel) in which case it applies for all further graphics object of the appropriate type that are created within the container object (unless there is some overriding setting.)
However, you cannot set a default property against a class of container objects to control properties that are not properties of that kind of container. Only against instances of the class.
figu = uifigure();
panu = uipanel(figu);
set(panu, 'defaultuicontrolHorizontalAlignment', 'right');
That would apply to all uicontrol created within panu after that time (unless there was further overwriting of properties). But you cannot do
set(groot, 'defaultuipaneluicontrolHorizontalAlignment', 'right')
to try to say that within uipanel that uicontrol HorizontalAlignment is to default to the given value.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by