필터 지우기
필터 지우기

Hide and disable uicontrols in groups

조회 수: 35 (최근 30일)
Matt J
Matt J 2013년 4월 18일
댓글: Eric Sargent 2020년 12월 9일
I'm designing GUIs where, sometimes, I want whole groups of uicontrols to be hidden from and inaccessible to the user. The tedious way to do this would be to set the Enable and Visibility properties to 'off' for each button individually. However, I was hoping for some way to designate them as a group and hide them using a single property set.
My first thought was to put them all on a uipanel and control them all through that. This works fine for controlling Visibility. Setting the panel's visibility property off hides everything. However, there doesn't seem to be a corresponding Enable property in a uipanel that can be used to deactivate all the uicontrols residing within it. I tried the HitTest property. That didn't work.
Any recommendations for how best to do this?
  댓글 수: 1
Eric Sargent
Eric Sargent 2020년 12월 9일
As of R2020b ButtonGroup and Panel both support Enable when the button group or panel is parented to a uifigure.

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

채택된 답변

Image Analyst
Image Analyst 2013년 4월 18일
I think you can pass in an array of handles to set()
% Get all the handles to everything we want to set in a single array.
handleArray = [handles.editText, handles.pushbutton, handles.listbox];
% Set them all disabled.
set(handlesArray, 'Enable', 'off');
  댓글 수: 4
Walter Roberson
Walter Roberson 2013년 4월 19일
set( findall(handles.your_uipanel, '-property', 'Enable'), 'Enable', 'off')
Matt J
Matt J 2013년 4월 29일
Nice one, Walter! If you convert it to an Answer, I'll +1 it.

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

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2013년 4월 29일
If you are writing the GUI programatically, I suggest writing your own uipanel class. This class would wrap around a regular panel and farm almost all commands to this uipanel. You could then add the properties you want to this class and have it internally disable all of its children. I.e. setting the 'Enable' property of this class will disable all of the children of the uipanel.
You'll end up doing essentially the same thing IA or Walter described but hide it in this class. It's also very reusable for future GUIs.
I did something similar with my pointyColorbar class and a few other classes I've written when I wanted to add a property to a predefined HG object.
  댓글 수: 4
Matt J
Matt J 2013년 4월 29일
편집: Matt J 2013년 4월 29일
That sounds like it would work. I guess you could flag the uipanels in GUIDE that you want to supe-up using its UserData.
Sean de Wolski
Sean de Wolski 2013년 4월 30일
If get() and set() in your class extended uipanel class properly overloaded getting and setting the regular properties to the uipanel (e.g: BorderType or FontUnits), then replacing the handle in the handles struct with that of your object should be okay.
i.e.
handles.uipanel1 = hExtendedPanel(handles.uipanel1);
guidata(handles.figure1,handles)
Now nothing would need to be stored in UserData, nothing would seemingly change anywhere else, but you would have an extended uipanel!

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


Eric Sargent
Eric Sargent 2020년 12월 9일
As of R2020b ButtonGroup and Panel both support Enable when the button group or panel is parented to a uifigure.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by