【问题标题】:Removing cursor from Matlab edit uicontrol after user has updated it?用户更新后从 Matlab 编辑 uicontrol 中删除光标?
【发布时间】:2021-10-17 11:22:14
【问题描述】:

向所有 Matlab 向导致敬 --

如果这是一个微不足道的问题,我深表歉意。在用户按下“enter”(并调用回调)后,如何从编辑 uicontrol 框中删除闪烁的光标?我认为默认情况下按“enter”会删除光标,因为用户已经“完成”了输入,但没有。我以为“selected”是属性,但不,那是不同的。

我无法通过谷歌搜索找到这个(后者大部分时间都有效)。

干杯!

【问题讨论】:

  • 把焦点移到别的地方,也许是下一个uicontrol。
  • 谢谢你,斯塔克。似乎这只会将问题转移到另一个uicontrol。我不希望将焦点放在任何 uicontrol 上,而是将焦点放在“焦点”中的图形(与顶部不同)——即处于无花果再次接受 ButtonDnFcn 回调的状态,无需单击在它的任何地方。

标签: matlab user-interface uicontrol


【解决方案1】:

您可以使用dummy uicontrol 来复制(我认为)您所追求的行为,请参阅此示例代码,它可以为您提供所需的行为

% create a figure
f = figure;
% set keypress and button down callbacks
f.KeyPressFcn = @(a,b)disp('press on figure' );
f.ButtonDownFcn = @(a,b)disp('button on figure' );
% create a dummy uicontrol as a text object with no text
t = uicontrol ( f, 'style' , 'text' );
% create a edit control
% set the callback to move the foccus to the dummy uicontrol
e = uicontrol ( f, 'style', 'edit', 'Callback', @(a,b)uicontrol(t) );
% set the key press and the button down callbacks of the dummy figure
% to run the callbacks of the figure
t.KeyPressFcn= @(obj,evt)feval(f.KeyPressFcn);
t.ButtonDownFcn= @(obj,evt)feval(f.ButtonDownFcn);

现在,当您在编辑框中输入文本并按下回车键时,焦点将移动到新的 uicontrol,其中回调链接到图形回调

【讨论】:

    【解决方案2】:

    这是我的问题的解决方案(灵感来自 https://uk.mathworks.com/matlabcentral/answers/65223-deselect-uimenus-after-click-in-gui

    %callback function for the control
    function update_control (hdl,event)
                set(hdl, 'Enable', 'off');
                drawnow;
                set(hdl, 'Enable', 'on');
    set(gcf,'CurrentObject',default_object);
    

    这会移除闪烁的光标并将 GUI 交互性返回到用户正在与之交互的上一个对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-23
      • 2018-07-29
      • 2018-08-07
      • 2017-10-18
      • 2020-09-25
      • 1970-01-01
      • 2019-02-15
      • 1970-01-01
      相关资源
      最近更新 更多