Azzera filtri
Azzera filtri

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

29 visualizzazioni (ultimi 30 giorni)
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 Commenti
RST il 28 Set 2023
So would I. Surely there must be way without using a GUIDE-style uifigure...

Accedi per commentare.

Risposte (2)

Pranav Verma
Pranav Verma il 11 Nov 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:
  1 Commento
Duijnhouwer il 11 Nov 2020
Modificato: Duijnhouwer il 11 Nov 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.

Accedi per commentare.

RST il 20 Feb 2024
Modificato: RST il 9 Mag 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
properties (Access = public)
ValueChangedFcn function_handle {mustBeScalarOrEmpty(ValueChangedFcn)};
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UIFigure.WindowStyle = 'modal';
% Button pushed function: Button1
function Button1Pushed(app, event)
if ~isempty( app.ValueChangedFcn)
app.ValueChangedFcn( 1 );
delete( app );
% Button pushed function: Button2
function Button2Pushed(app, event)
if ~isempty( app.ValueChangedFcn)
app.ValueChangedFcn( 2 );
delete( app );
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;
This appears to be working for me in R2023a. I think it should work since R2020b when WindowStyle 'modal' was introduced.


Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by