change the QUESTDLG box size
47 次查看(过去 30 天)
显示 更早的评论
Hello,
I was wondering if it is possible to change the window size that QUESTDLG function creates, as the title that I have is not completly being shown in the border of the box.
3 个评论
dpb
2022-8-29
编辑:dpb
2022-8-29
You really think anybody ever reads those titles, anyway??? :)
I'm sure at the OS level on which the dialogs are built there is the facility to do so but it's never been a visible property to the MATLAB high-level function which has been around since prior to R2006a (the point at which the archival research regarding incorporation dates was halted for the documentation).
BTW, if you're using AppDesigner or uifigure it is recommended to use uiconfirm instead -- and no, it doesn't have the facility you're looking for, either, I already checked!
采纳的回答
Image Analyst
2022-8-29
编辑:Image Analyst
2022-8-29
Try this utility questdlgbig, which replaces questdlg() and lets you specify a font size so things are bigger.
% Like questdlg() but this one lets you specify the font size so that it's bigger and easier to see.
%
% Sample calls
% promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
% dialogTitleString = 'Continue?';
% No font size specified. Use default of 16.
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, opts);
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, choice2, opts); % Have default be choice2.
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, choice3, opts); % Three distinct choices.
% A font size was specified.
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, opts, 17);
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, choice3, opts, 17); % Three distinct choices.
%
% For example, to check on which button they clicked on, use contains to see if it contains a unique word from one of your choices.
% if contains(buttonText, 'Quit', 'IgnoreCase', true)
% return; % or break or continue.
% end
function buttonText = questdlgbig(varargin)
try
buttonText = ''; % Initialize.
% nargin
% celldisp(varargin)
if nargin < 5
celldisp(varargin)
uiwait(errordlg('Not enough input arguments to questdlgbig.'));
return;
end
% See if any of the inputs is a number. If so, consider it to be the font size.
fontSize = 16; % Initialize
inputArguments = varargin'; % Initialize.
for k = 1 : nargin
if isnumeric(inputArguments{k})
% It's a number.
fontSize = inputArguments{k};
% Remove that cell
inputArguments(k) = [];
break;
end
end
% Parse the arguments
promptMessage = inputArguments{1};
dialogTitleString = inputArguments{2};
choice1 = inputArguments{3};
choice2 = inputArguments{4};
choice3 = [];
numInputs = numel(inputArguments);
% Determine if it's a 2 choice or 3 choice situation.
% Note: if the call is like this:
% buttonText = questdlg(promptMessage, dialogTitleString, choice1, choice2, choice3, fontSize);
% Then if choice3 is equal to choice1 or choice2, then it's a two-choice situation
% and choice3 would be the default choice and should equal either choice1 or choice2.
% If choice2 does not equal either choice1 or choice2, then it's a 3 choice situation.
% That's just the way questdlg operates.
if numInputs >= 5
% Potentially three choices. Can't specify default button in arg list but you can as part of opts.
choice3 = inputArguments{5};
if strcmp(choice3, choice1)
% Choice3 matched choice2.
% So this is a "Two choices" situation. Can specify default button.
choice3 = [];
opts.Default = choice1; % The third input is the default and should be either choice1 or choice2.
elseif strcmp(choice3, choice2)
% Choice3 matched choice2.
% So this is a "Two choices" situation. Can specify default button.
choice3 = [];
opts.Default = choice2; % The third input is the default and should be either choice1 or choice2.
else
% Three choice situation.
% strangely enough with 3 choices, you cannot specify the default button
% yet you must still have a "Default" field for opts.
opts.Default = choice1; % Just say the default is choice1.
end
else
% Two choices but they forgot to specify a default.
opts.Default = choice1; % Just say the default is choice1.
end
% If there is a backslash in the string (like from a folder), then it needs to be replaced by double backslashes.
promptMessage = strrep(promptMessage, '\', '\\');
% Replace underlines with \_ so the next character won't be a subscript.
promptMessage = strrep(promptMessage, '_', '\_');
opts.Interpreter = 'tex';
opts.WindowStyle = 'modal';
% Embed the required tex code in before the string.
latexMessage = sprintf('\\fontsize{%d}%s', fontSize, promptMessage);
if isempty(choice3)
% Two choices.
buttonText = questdlg(latexMessage, dialogTitleString, choice1, choice2, opts);
else
% Three choices.
% With 3 choices, you can either specify a default option, or opts (font size) but NOT BOTH.
% Here we go with the opts.
buttonText = questdlg(latexMessage, dialogTitleString, choice1, choice2, choice3, opts);
end
catch ME
errorMessage = sprintf('Error in questdlgbig():\n%s', ME.message);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
return; % from questdlgbig()
For example
buttonText = questdlgbig('Which do you want?', 'Your choice?', 'Choice 1', 'Choice 2', 17)
gives
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1111260/image.png)
and
buttonText = questdlgbig('Which do you want?', 'Your choice?', 'Rock', 'Hard Place', 'Quit', 17)
gives
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1111265/image.png)
6 个评论
Image Analyst
2022-8-29
Well if you think this is the best solution, could you please click on the "Accept this answer" link? Thanks in advance. 🙂
dpb
2022-8-29
NB that you're not just adding spaces -- the blanks have to be followed by a printing character because the control will strtrim() the passed string before displaying it.
Just playing here the example above wasn't yet enough to not cut off the title text with default; it turns out
>> q='Enter a number: .'; % IA's string
>> sum(q==' ') % how many blanks? Turns out 33 after the : weren't enough
ans =
35
>> q=['Enter a number: ' blanks(50) '.']; % make a new, longer one
>> resp=questdlg(q, 'Enter your answer', '1', '2', '1')
resp =
'1'
>>
The last was finally(!) enough to show the title in its entirety; I didn't iterate to find the minimum number that would work -- it would also depend upon the default font one is using I expect....
Amazing how long one can fiddle around with such trivial details!!! :)
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!