October 28, 2018

MATLAB bug: Why does QUESTDLG return the wrong button string if I use the TAB key to switch between different buttons and then hit the Return key?


The UI MATLAB function questdlg has following issue:

If you use questdlg and use the TAB key to switch different button and press the ENTER key to validate your selection, the returned selected Button is always the Default button.

The issue is described in details in the Support Knowledge base 1-3MB2SF.

Below a short screencast to demonstrate it:
It is still not solved in MATLAB R2015b.
As mentioned in the Answer here, this issue can be fixed easily by adding/editing 2 lines in questdlg:
Change the KeyPressFcn callback to:

function cb_KeyPressFcn(obj,evd)
switch(evd.Key)
    case {'return','space'}
        ButtonName=get(get(figureHandle,'CurrentObject'),'String');
        setappdata(figureHandle,'ButtonName',ButtonName);
        uiresume(gcbf);
    case 'escape'
        doDelete
end

and after the uiwait change the line:

ButtonName=get(get(QuestFig,'CurrentObject'),'String');

into:

ButtonName=getappdata(figureHandle,'ButtonName');
if isempty(ButtonName), % no KeyPress/ MouseClick,
    ButtonName=get(get(figureHandle,'CurrentObject'),'String');
end


This fix is implemented in the myquestdlg available in my .


Note:

It is still required to used a drawnow after a myquestdlg call, because of some MATLAB hanging issues.


Related Posts:

No comments:

Post a Comment