GUI, make a handle disappear

조회 수: 1(최근 30일)
Marc Martinez Maestre
Marc Martinez Maestre 2020년 8월 19일
댓글: Marc Martinez Maestre 2020년 8월 24일
Hey, I am MArc and I have a question about a GUI. have this GUI interface:
I want to achieve that when clicking both pink clickboxes I want to make all the red handles disappear. I tried with a function using the button 2, like this:
methods (Access = private)
function Button2Pushed(app, event,handles)
value1= get(handles.PRETESSATRECTECheckBox,'Value')==0;
value2= get(handles.PRETESSATENCASTAMENTCheckBox,'Value')==0;
value3= get(handles.PRETESSATPARABLICCheckBox,'Value')==1;
value4= get(handles.ntramsCheckBox,'Value')==1;
if value1 && value2 && value3&& value4
set(handles.LmEditField_3, 'Visible', 'off');
set(handles.readelaseccim2EditField_2, 'Visible', 'off');
set(handles.LNmEditField_2, 'Visible', 'off');
set(handles.Inrciam4EditField_2, 'Visible', 'off');
set(handles.AmpladadelaseccimEditField_2, 'Visible', 'off');
set(handles.ncordonsEditField_2, 'Visible', 'off');
set(handles.Sigma_uMPaEditField_2, 'Visible', 'off');
set(handles.Sigma_yMPaEditField_2, 'Visible', 'off');
set(handles.CargapermanentKNm2EditField, 'Visible', 'off');
set(handles.SobrecargavariableKNm2EditField, 'Visible', 'off');
set(handles.SobrecargavariableKNEditField, 'Visible', 'off');
set(handles.PuntualKNEditField, 'Visible', 'off');
set(handlesD_vainammEditField, 'Visible', 'off');
set(handles.LmEditField_3, 'Visible', 'on');
But it does not work, it does nothing. I would like some advice, thank you
  댓글 수: 6
Rik 2020년 8월 20일
Change this
function CheckBoxValueChanged(app, event)
to this
function CheckBoxValueChanged(app, event)
uiwait(msgbox('the function was called'));
Then you know for sure if it is called or not.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 8월 19일
"I want to achieve that when clicking both pink clickboxes I want to make all the red handles disappear. "
The function you shared requires two checkboxes to be not-selected and two to be selected. That doesn't match your description.
Also, the checkbox detection needs to happen when any of the applicable checkboxes are toggled. If the detection only exists in 1 checkbox callback, toggling the other one will have no effect.
To avoid having 2 copies of the same code, assign the same CheckBoxValueChanged function to each applicable checkbox.
function CheckBoxValueChanged(app, event)
% Get values of all checkboxes
cb(1) = app.CheckBox.Value;
cb(2) = app.CheckBox2.Value;
% Toggle the visibility flag depending on checkbox states
if all(cb)
visibleFlag = 'off';
visibleFlag = 'on';
app.LNmEditField_2.Visible = visibleFlag;
app.LmEditField_3.Visible = visibleFlag;
% etc...
  댓글 수: 5
Marc Martinez Maestre
Marc Martinez Maestre 2020년 8월 24일
Thank you soo much, really awesome answer and really guided. Thank you

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Ruger28 2020년 8월 19일
As suggested above, make all of the items you would like to "disappear" (turn visibility off) by lumping them together in a single handle. Below is a quick example I threw together.
% in the opening function before gui is made visible
handles.MyEditBoxes = [handles.edit1,handles.edit2,handles.edit3,handles.edit4,handles.edit5];
Then for your pushbutton, get the values of the two checkboxes, and AND them.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
value1 = get(handles.checkbox1,'Value');
value2 = get(handles.checkbox2,'Value');
if value1 && value2
This will hide/unhide the items in MyEditBoxes.
  댓글 수: 1
Marc Martinez Maestre
Marc Martinez Maestre 2020년 8월 20일
Thank you Ruger28 but, how would it be to set the visibility off only by clicking two checkboxes?
Thank you

댓글을 달려면 로그인하십시오.





Community Treasure Hunt

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

Start Hunting!

Translated by