How do I add .editable behavior to .mlapp components?

3 次查看(过去 30 天)
Some mlapp components have a .editable property that allows or disallows editing of the value. An example is the numeric edit field, where you can allow or disallow editing the value displayed by setting the .editable property for the component. However, not all components that hold a value have a .editable property. An example of this is the check box. The check box has a value (app.checkbox.Value) that can be changed by clicking the check box, but there is no .editable property that I can set to allow or disallow this editing.
Is there a way to add this .editable property and behavior to mlapp components that lack it? examples of components that lack the behavior include the check box, switch, dropdown menu.
For context: I'm building a gui in the matlab app designer that will control an expensive piece of equipment. The equipment has many settings that the user may adjust via the gui. I have a switch on the gui called "enable editing" that sets the .editable status of all edit fields to off unless the switch is flipped to the on state. This acts as a safety to prevent unintended and potentially damaging changes to the configuraion. This setup works perfectly for all of the numeric edit fields but I can't figure out how to add this safety feature to check boxes, switches, and dropdowns.
It is possible to set the .enable property on these components to off, but that has unintended consequences from a user interface perspective. Components are greyed out and very hard to see while disabled, which communicates to the user that the setting is not relevant, isn't used, or something along those lines. That's not at all what I want. The current state of the check box is extremely important and should remain perfectly visible - I just don't want a misclick to change its status. I've made a quick dummy app showing the difference using a check box. A screenshot is shown below.

采纳的回答

Cris LaPierre
Cris LaPierre 2023-3-30
编辑:Cris LaPierre 2023-3-30
There is not an 'Editable' property for checkboxes. Since it appears you want the checkbox to be view only, which means its value is getting set programmatically elsewhere in your app, you could make the checkbox callback just be a function that returns the checkbox back to whatever value it had before.
% Value changed function: CheckBox
function CheckBoxValueChanged(app, event)
value = app.CheckBox.Value;
if value==1
app.CheckBox.Value = 0;
else
app.CheckBox.Value = 1;
end
end
  4 个评论
Jeff
Jeff 2023-3-30
编辑:Jeff 2023-3-30
I just tried this and it works. It's a little hacky but it gets the job done for now. The downside is the value still does change for a moment - the checkbox flickers when I click it while editFlag is false but it does quickly resume its prior state. This could be an issue for other applications where a momentary change in the state is a problem but it's not a concern for my application.
I think this is something that should be looked at for a future release though. It seems to me that a Value property should always go hand-in-hand with an Editable property. There's no fundamental difference between a numeric edit field and a check box - they're both ui components that store a value and may be changed by the user. The only difference is the domain of valid Values and how it appears on the interface. If one has an Editable property, all others should as well.
Cris LaPierre
Cris LaPierre 2023-3-30
Agreed. Consider submitting a suggestion saying as much here:
(Create Service Reqeust > Technical Support > Product help, bugs, suggestions or documentation errors)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by