Initially Disabled Button Group when using GUI / GUIDE

3 次查看(过去 30 天)
Hello all,
I have an easy GUI question that I can't find the answer to - I can't figure out where to specify that a button group is initially disabled instead of enabled.
In my simplified example, I want to have a check-box that has a disabled (greyed-out) button group below it, until the check-box is selected by the user.
I have gone over similar questions in the forum, and I have found that the way to change the status of the button group is:
function MattsCheckBox_Callback(hObject, eventdata, handles)
if get(hObject,'Value')
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'on');
else
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'off');
end
When I click back and forth on the check-box, sure enough my button group enables and disables. However, before I do any clicking of the check box, the button group starts enabled instead of disabled. Where (or how) do I initialize the button group so that it starts disabled and greyed-out?

采纳的回答

Matt C
Matt C 2016-9-8
I figured it out. There isn't any default disablement of the Button Group - it needs to be coded into the disabled position at the beginning of the code under the _OpeningFcn function. Here is the code:
function MattsTestScript_OpeningFcn(hObject, eventdata, handles, varargin) % Default line produced by GUIDE
handles.output = hObject; % Default line produced by GUIDE
guidata(hObject, handles); % Default line produced by GUIDE
set(findall(handles.MattsButtonGroup, '-property', 'enable'), 'enable', 'off'); % HERE IT IS

更多回答(1 个)

mbonus
mbonus 2016-9-8
If the value you are checking in the if statement is true when the GUI starts up, that may be causing the button group to start enabled. For the check box set the value property to 0. Also check to make sure the button group is initialized to 'enable' 'off'. From Guide you should be able to right click the objects and changer their properties, I believe if you hardcode it during the initialization in the code it will work as well, not sure because I don't use Guide.

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by