我在尝试制作MATLAB GUI时出现问题 automatically resizeable . 在彻底搜索网络寻求帮助和大量测试之后,我找不到解决方案 .
我一直在我的笔记本电脑( Screen size/resolution = 1366x768 )中开发一个简单的GUI(使用MATLAB,不使用GUIDE) . 一个非常简化的版本如下所示:
当我在台式计算机( Screen size/resolution = 1920x1080 )中运行相同的GUI时,它以下列方式显示:
考虑到屏幕尺寸( the code is provided in the bottom of this post ),GUI的尺寸会自动初始化 . 如您所见(红色箭头突出显示),组件之间的字体/间距不会自动调整大小,因此无论我们在何处运行文件,GUI都具有相同的方面 .
此外,当手动调整GUI大小时,会出现一些组件重叠:
用于此最小工作示例的代码如下:
function resizingGUIexample()
%% SET UP GUI
hdl.mainfig = figure();
% MANAGE FIGURE DIMENSIONS -------------------------------------------------------------------------------------
set(hdl.mainfig, 'Units', 'pixels');
dims = get(0, 'ScreenSize');
screenHeight = dims(4);
verticalMargins = floor((0.2*screenHeight)/2); % =10% of the screen height in each side
figureHeight = (0.8*screenHeight);
figureWidth = (0.8*screenHeight)*(4/3); % 4/3 Aspect Ratio
set(hdl.mainfig, 'Position', [0, verticalMargins, ...
figureWidth, figureHeight]);
movegui(hdl.mainfig,'center') % move GUI to center
color = get(hdl.mainfig,'Color'); % get background color to hide static texts, etc...
% AXES ---------------------------------------------------------------------------------------------------------
hdl.axes = axes('Parent', hdl.mainfig, ...
'Units', 'Normalized', ...
'Position', [0.295 0.05 0.63 0.63*(4/3)]);
% PUSH BUTTONS -------------------------------------------------------------------------------------------------
hdl.donePB = uicontrol(hdl.mainfig, ...
'Position', [0.85 0.91 0.075 0.075], ...
'String', 'Done', ...
'Fontsize', 16, ...
'Units', 'normalized', ...
'FontWeight', 'Bold');
% BUTTON GROUP and RADIO BUTTONS -------------------------------------------------------------------------------
hdl.buttonGroup = uibuttongroup('Parent', hdl.mainfig, ...
'FontSize', 16, ...
'FontWeight', 'Bold', ...
'BackgroundColor', color, ...
'Units', 'Normalized', ...
'Position', [0.05 0.69 0.2 0.2]);
titleBG = sprintf('Intensity\nNormalization');
set(hdl.buttonGroup, 'Title', titleBG);
hdl.VolumeRB = uicontrol(hdl.buttonGroup, ...
'Style', 'radiobutton', ...
'String', 'Volume', ...
'FontSize', 14, ...
'FontWeight', 'Bold', ...
'Units', 'normalized', ...
'BackgroundColor', color, ...
'Position', [0.1 0.67 0.8 0.3]);
hdl.SliceRB = uicontrol(hdl.buttonGroup, ...
'Style', 'radiobutton', ...
'String', 'Slice', ...
'FontSize', 14, ...
'FontWeight', 'Bold', ...
'Units', 'normalized', ...
'BackgroundColor', color, ...
'Position', [0.1 .25 0.8 0.3]);
end
关于如何解决这些问题的任何想法?
非常感谢提前 .
亲切的问候,
FábioNery
EDIT1: 我也非常愿意接受有关更好地初始化GUI维度和策略的建议,以避免在不同监视器/屏幕分辨率下运行GUI时出现问题 .