【问题标题】:Matlab UIControl UnitsMatlab UI控制单元
【发布时间】:2012-07-17 14:14:05
【问题描述】:

我正在使用 uicontrol 创建 GUI 元素。以下是我的代码

uicontrol('Style','pushbutton', 'String','Load data','Parent',hTabs(1),'Position',[250 825 80 20], 'Callback',@ButtonCallback);

这里的问题是当我使用单位标准化选项时,GUI 元素正在从屏幕上消失。我想使用规范化,以便 GUI 在不同的屏幕分辨率下自行调整。对此的任何想法都会对我非常有帮助。

【问题讨论】:

    标签: matlab screen-resolution uicontrol


    【解决方案1】:

    当您使用Normalized 单位时,您需要定义介于 0 和 1 之间的位置,其中 0 是底部/左侧,1 是包含对象的总高度/宽度。

    您当前正在使用远远超出此范围的数字来定义位置。你可以做两件事。

    • 在单独的函数调用中将单位切换为normalized(如下所示)
    • 使用标准化单位创建uicontrol,但您必须计算正确的位置向量

    以下是关于如何做的示例

    一个简单的解决方案是创建uicontrol,然后在单独的调用中将单位设置为标准化

    u = uicontrol(...) %don't specify the units
    set(u,'Units', 'Normalized'); % this solves your problem
    

    如果你想得到归一化单位的位置向量

    normPos = get(u, 'Position') % get the position in normal space
    

    然后使用这些数字创建具有标准化单位的uicontrol

    u = uicontrol(...,'Units','Normalized', 'Position', normPos); 
    

    【讨论】:

      【解决方案2】:

      使用'units','normalized' 选项时,您必须更改位置矢量。图形参考系统的坐标介于 0 和 1 之间。

      例如

      uicontrol('Style','pushbutton',...
                'String','Load data',...
                'Parent',hTabs(1),...
                'units','normalized',...
                'Position',[0 0 0.1 0.1],...
                'Callback',@ButtonCallback); 
      

      在父面板的左下角为您提供一个 10% 的高度和宽度的按钮。

      【讨论】:

        猜你喜欢
        • 2012-06-18
        • 1970-01-01
        • 2013-06-15
        • 2012-02-04
        • 2018-07-22
        • 1970-01-01
        • 2013-11-11
        • 1970-01-01
        相关资源
        最近更新 更多