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 个评论
Mehrdad Bahadori
Mehrdad Bahadori 2022-8-29
Thanks for your reply.
It looks weird though! This is something that I think should be adjustable. Not always we can shorten the title
dpb
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
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
and
buttonText = questdlgbig('Which do you want?', 'Your choice?', 'Rock', 'Hard Place', 'Quit', 17)
gives
  6 个评论
Image Analyst
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
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 个)

Mehrdad Bahadori
Mehrdad Bahadori 2022-9-6
编辑:Mehrdad Bahadori 2022-9-6
okay then...
looking more into this trivial detail, I found even a more intersting thing to add here!
using the code below, you can add an additional part to your string, in which you can change its color to something close to the background of the questionbox, then you wont see even the "." that you inserted in the end :)
In the end, by modifying the space placed at the end of the question (here 'Starting calibration?'), you can find the sufficient width for your box in order to have all the title visible.
opts.Interpreter = 'tex';
opts.Default = 'Yes';
answer = questdlg(['Starting calibration? ','\color[rgb]{0.9,0.9,0.9} .'], ...
'Calibration phase', ...
'Yes','No',opts);

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by