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

29 Ansichten (letzte 30 Tage)
Duijnhouwer
Duijnhouwer am 31 Jul. 2020
Bearbeitet: RST am 20 Feb. 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 Kommentare
Rick
Rick am 15 Mär. 2023
I would very much like this functionality too.
RST
RST am 28 Sep. 2023
So would I. Surely there must be way without using a GUIDE-style uifigure...

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Pranav Verma
Pranav Verma am 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:
Thanks
  1 Kommentar
Duijnhouwer
Duijnhouwer am 11 Nov. 2020
Bearbeitet: Duijnhouwer am 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.
Cheers,
Jacob

Melden Sie sich an, um zu kommentieren.


RST
RST am 20 Feb. 2024
Bearbeitet: RST am 20 Feb. 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.

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by