Is there a generic modal dialog for appdesigner that can be customized?

29 visualizaciones (últimos 30 días)
Duijnhouwer
Duijnhouwer el 31 de Jul. de 2020
Editada: RST el 20 de Feb. de 2024
I like the modal uialert and uiconfirm dialogs in appdesigner.
Is there a way to make custom dialogs that behave like those (that is, stick within the bounds of the UIFigure and darken it)
I would like to make dialogs like that but be able to add custom buttons, check boxes, pulldown menus, etc to them
  3 comentarios
Rick
Rick el 15 de Mzo. de 2023
I would very much like this functionality too.
RST
RST el 28 de Sept. de 2023
So would I. Surely there must be way without using a GUIDE-style uifigure...

Iniciar sesión para comentar.

Respuestas (2)

Pranav Verma
Pranav Verma el 11 de Nov. de 2020
Hi Duijnhouwer,
From your query I understand that you need a way in MATLAB to create a customizable dialog box. Please refer to the below link which explains the functions and examples to create a customizable dialog box:
Thanks
  1 comentario
Duijnhouwer
Duijnhouwer el 11 de Nov. de 2020
Editada: Duijnhouwer el 11 de Nov. de 2020
Hi, Thanks for your answer but dialog creates a regular dialog.
I'm looking for the equivalent for use in the new appdesigner style.
For example, the existing command "uialert"
Creates a uialert dialog as a child of a uifigure, and is contained within the boundaries of that uifigure and disables all interaction with the children (for example buttons) of the parent uifigure until the dialog has been dealt with.
Besides uialert, there are uiconfirm, and a uiprogressdlg which look nice.
What i'm hoping for is a more generic "uidialog" function that can have any custom UI elements. For example to prompt the user to enter some numbers, or pick an item from a list, etc.
Cheers,
Jacob

Iniciar sesión para comentar.


RST
RST el 20 de Feb. de 2024
Editada: RST el 20 de Feb. de 2024
Since R2020b we can make a custom AppDesigner modal dialog by using these features:
  • app.UIFigure.WindowStyle = 'modal'
  • uiwait() on our app.UIFigure
  • a callback property in the app, and
  • a function to create and wait on the app, with a nested function for the callback
This app is modal, has two buttons, and a ValueChangedFcn property. Here is a snip of the relevant AppDesigner code:
classdef modalApp1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button2 matlab.ui.control.Button
Button1 matlab.ui.control.Button
end
properties (Access = public)
ValueChangedFcn function_handle {mustBeScalarOrEmpty(ValueChangedFcn)};
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UIFigure.WindowStyle = 'modal';
end
% Button pushed function: Button1
function Button1Pushed(app, event)
if ~isempty( app.ValueChangedFcn)
app.ValueChangedFcn( 1 );
end
delete( app );
end
% Button pushed function: Button2
function Button2Pushed(app, event)
if ~isempty( app.ValueChangedFcn)
app.ValueChangedFcn( 2 );
end
delete( app );
end
end
The startupFcn sets the WindowStyle to be 'modal'. The button callbacks call the ValueChangedFcn callback to pass on the result and then delete() the app.
Now we want a function that displays the app, hooks into the callback and then waits for the app to close. It returns [] if the app is closed, or 1 or 2 according to the button pressed.
function result = showModalApp()
result = []; % result, set by nested funcion
hMA = modalApp1(); % show tha app
hMA.ValueChangedFcn = @valueChanged; % set nested function
uiwait(hMA.UIFigure); % wait for the app to close
function valueChanged( val )
% collect the result to a variable in the parent function
result = val;
end
end
This appears to be working for me in R2023a. I think it should work since R2020b when WindowStyle 'modal' was introduced.

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by