Removing cursor from Matlab edit uicontrol after user has updated it?

130 Views Asked by At

Hi to all Matlab wizards --

I apologize if this is a trivial question. How does one remove the blinking cursor from an edit uicontrol box after the user had pressed "enter" (and the callback got invoked)? I thought pressing "enter" would remove the cursor by default, since the user is "done" with the input, but no. I thought "selected" would be the property, but no, that's different.

I could not find this by googling (the latter works most of the time).

Cheers!

2

There are 2 best solutions below

0
matlabgui On

You can use a dummy uicontrol to replicate the behaviour that (I think) you are after, see this example code which gives you the behaviour you want

% 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);

Now when you enter text into the edit box and press enter the focus moves to the new uicontrol where the callbacks are linked to the figure callbacks

0
runcyclexcski On

This was the solution to my problem (inspired by 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);

This removes the blinking cursor and returns the GUI interactivity to the previous object that the user was interacting with.