How to change automatically generated uibutton properties in another function?

3 Ansichten (letzte 30 Tage)
The following code is run at startup that generated buttons based on a number of unique files in a folder. The callbackfcn is another function, where the user would choose one of these buttons. At that point, i'd like to highlight the chosen button, which is easy, but i would also like to grey out, or delete the other buttons. The qquestion is how to I access the other buttons that were generated?! I can get to the button that was clicked easily, just not the other ones.
%
% make buttons
numButtons = max(size(app.orientationUnique));
for b = 1:numButtons
posidx = b*(30+app.TheHuntGUI.Position(1));
app.orientationButtons = uibutton(app.TheHuntGUI, 'push');
app.orientationButtons.FontName = 'Arial';
app.orientationButtons.FontSize = 18;
app.orientationButtons.FontWeight = 'bold';
app.orientationButtons.Position = [posidx 500 120 40];
app.orientationButtons.Text = app.orientationUnique{b};
app.orientationButtons.Tag = app.orientationUnique{b};
app.orientationButtons.ButtonPushedFcn = createCallbackFcn(app, @orientationButtonPushed, true);
end
  1 Kommentar
sid
sid am 23 Nov. 2021
Resolved.
numButtons = max(size(app.orientationUnique));
for b = 1:numButtons
posidx = b*(30+app.TheHuntGUI.Position(1));
app.orientationButtons(b) = uibutton(app.TheHuntGUI, 'push');
set(app.orientationButtons(b),'FontName','Arial');
set(app.orientationButtons(b),'FontSize',18);
set(app.orientationButtons(b),'FontWeight','bold');
set(app.orientationButtons(b),'Position',[posidx 500 120 40]);
set(app.orientationButtons(b),'Text', app.orientationUnique{b});
set(app.orientationButtons(b),'Tag',app.orientationUnique{b});
set(app.orientationButtons(b),'ButtonPushedFcn',createCallbackFcn(app, @orientationButtonPushed, true));
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mohammad Sami
Mohammad Sami am 22 Nov. 2021
You can store all your buttons as an array in the app property orientationButtons.
function create_buttons(app)
% % make buttons
numButtons = max(size(app.orientationUnique));
for b = 1:numButtons
posidx = b*(30+app.TheHuntGUI.Position(1));
app.orientationButtons(b) = uibutton(app.TheHuntGUI, 'push');
app.orientationButtons(b).FontName = 'Arial';
app.orientationButtons(b).FontSize = 18;
app.orientationButtons(b).FontWeight = 'bold';
app.orientationButtons(b).Position = [posidx 500 120 40];
app.orientationButtons(b).Text = app.orientationUnique{b};
app.orientationButtons(b).Tag = app.orientationUnique{b};
app.orientationButtons(b).ButtonPushedFcn = createCallbackFcn(app, @orientationButtonPushed, true);
end
end
function orientationButtonPushed(app,event)
btnclicked = event.Source;
allotherbtns = app.orientationButtons(~ismember(app.orientationButtons,btnclicked));
end
Also I suggest you use uigridlayout as the parent for your buttons. This will automatically adjust the sizes of the button based on the available space instead of manually setting the positions in code.
  3 Kommentare
Mohammad Sami
Mohammad Sami am 23 Nov. 2021
How did you access the fontname property. You need to but the index before the .FontName.
app.orientationButtons(b).FontName = 'Arial';
sid
sid am 24 Nov. 2021
resolved. cant get your solution to work, but the uigridlayout is a good idea. thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by