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

29 次查看(过去 30 天)
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 个评论
RST
RST 2023-9-28
So would I. Surely there must be way without using a GUIDE-style uifigure...

请先登录,再进行评论。

回答(2 个)

Pranav Verma
Pranav Verma 2020-11-11
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 个评论
Duijnhouwer
Duijnhouwer 2020-11-11
编辑:Duijnhouwer 2020-11-11
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

请先登录,再进行评论。


RST
RST 2024-2-20
编辑:RST 2024-5-9
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.

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by