【问题标题】:Set uibutton properties for a MATLAB button为 MATLAB 按钮设置 uibutton 属性
【发布时间】:2013-06-16 11:39:31
【问题描述】:

当程序忙于计算时,我正在尝试将我的 gui 按钮的背景颜色设置为不同的颜色。如果我只是在单击按钮时将颜色设置为更改,则它会更改;但是,如果我在实际计算之后添加另一行代码以将颜色更改回默认值,则颜色永远不会第一次更改。

function FitData_button_Callback(hObject, ~, handles) %#ok<DEFNU>

set(handles.FitData_button,'BackgroundColor',[0 204 0]./255,'String','Fitting Data');

% do some computation that takes time here...

% this line causes the first instance of 'set' not to work
set(handles.FitData_button,'BackgroundColor',[237 237 237]./255,'String','Fit Data'); 

如果我第二次更改属性,我调用“set”,它确实会从默认值更改为第二次指定的属性(并且它会在长时间计算完成后执行此操作)。但是,第一组属性永远不会被分配。 所以看起来我只能设置一次 BackgroundColor 和 String 属性,这没有任何意义。

什么给了? 谢谢

【问题讨论】:

  • 我尝试调用其他函数并执行一个简单的 disp('program is here') 来确认这些命令是按照它们列出的顺序被调用的。
  • 刚刚确认属性值在设置属性后立即发生变化,但刚刚开始计算。 function FitData_button_Callback(hObject, ~, handles) set(handles.FitData_button,'BackgroundColor',[0 204 0]./255,'String','Fitting Data'); get(handles.FitData_button,'String','Fitting Data') % 在这里进行需要时间的计算... % -- 不重置默认按钮属性。此时,上面的属性更改实际上是可见的。所以属性值会在它应该改变的时候改变,它只是在计算完成运行之后才可见。

标签: matlab button user-interface colors background


【解决方案1】:

简短的回答是在您的计算中间放置一个“drawnow”。长答案最好由 Yair Altman 在他的博客上说明(顺便说一句,这太棒了)-http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多