Pushbutton is not responsive until I move figure that pushbutton is attached to

조회 수: 2 (최근 30일)
I am encountering some strange behavior probably due to my lack of experience in designing small GUIs via Matlab.
I built a small menu for selecting some parameters related to the analysis I am running. This menu includes an "Accept" and "Cancel" button at the bottom of the figure.
function acceptButton(hObject, eventdata, handles)
%% set pars from menu AFTER button press
pars=setExptParsFromMenu(menu,pars);
close(menu.FigH)
quitProgram=false;
end
function cancelButton(hObject, eventdata, handles)
%% set pars from menu AFTER button press
close(menu.FigH)
quitProgram=true;
end
Upon hitting accept/cancel, I close the figure in order to move on with the program:
uiwait(menu.FigH)
All of my menu's fields--which include dropdown lists and text edit fields--work 100% as expected (code not shown). However, there is an odd "bug" with the accept/cancel buttons. The buttons do not work when I try to use them via their default location (bottom-right corner of my monitor). They do not even show the blue borderline that typically surrounds them when you hover a mouse over a pushbutton. If I move the figure a couple inches to the left, they suddenly work again. If I move the figure back to its initial location, they no longer work.
It's almost as if there is an invisible object between these buttons and the mouse, but I have no reason to think that any invisible object would be present. I do not use. Any ideas?
  댓글 수: 5
Chris Endemann
Chris Endemann 2019년 7월 31일
편집: Chris Endemann 2019년 7월 31일
Yes, they are nested functions. They aren't global variables. This should provide a better overview:
function [pars,quitProgram]=setExperimentGUI(pars)
quitProgram=true;
menu=struct;
%% init figure
xCenter=600;
yCenter=45;
figWidth=980;
figHeight=1000;
menu.FigH=figure('units','pixels',...
'position',[xCenter yCenter figWidth figHeight],...
'menubar','none',...
'numbertitle','off',...
'name','Experiment Params',...
'resize','off');
NEW_COL_SHIFT=180;
NEW_ROW_SHIFT=60;
%
START_XCENTER=xCenter-(figWidth/2);%+100;
START_YCENTER=yCenter+(figHeight)-100;
%
FIELD_HEIGHT=20;
FIELD_WIDTH=130;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% add buttons
uicontrol(menu.FigH,'style','pushbutton',...
'unit','pix',...
'position',[730 50 100 20],...
'Callback', @acceptButton,...
'string',{'Accept'});
uicontrol(menu.FigH,'style','pushbutton',...
'unit','pix',...
'position',[840 50 100 20],...
'Callback', @cancelButton,...
'string',{'Cancel'});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% add field1
menu=addDataTypeFields(menu,...
START_XCENTER,START_YCENTER,...
FIELD_WIDTH,FIELD_HEIGHT,...
NEW_ROW_SHIFT);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% add field2
menu=addPCAFields(menu,...
START_XCENTER+(NEW_COL_SHIFT*1),START_YCENTER,...
FIELD_WIDTH,FIELD_HEIGHT,...
NEW_ROW_SHIFT);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% wait
uiwait(menu.FigH)
function acceptButton(hObject, eventdata, handles)
%% set pars from menu AFTER button press
figure(menu.FigH)
pars=setExptParsFromMenu(menu,pars);
close(menu.FigH)
quitProgram=false;
end
function cancelButton(hObject, eventdata, handles)
%% set pars from menu AFTER button press
close(menu.FigH)
quitProgram=true;
end
end
I control each field of the menu by creating uicontrol objects. Some of them only appear conditionally, and default to invisible. Please note, though, that I can make all fields appear via the GUI and the accept button still does not work. Therefore, it doesn't look like an invisible object is covering something up. Furthermore, even if that were the case--it doesn't make sense why moving the figure would fix the problem. The functions that add fields look something like this:
function menu=addPCAFields(menu,...
START_XCENTER,START_YCENTER,...
FIELD_WIDTH,FIELD_HEIGHT,...
NEW_ROW_SHIFT)
xCenter=START_XCENTER;
yCenter=START_YCENTER;
%% pca bool (1)
menu.pca.bool=uicontrol(menu.FigH,'style','pop',...
'unit','pix',...
'position',[xCenter yCenter FIELD_WIDTH FIELD_HEIGHT],...
'Callback', @dispPCAfields,...
'string',[0,1]);
uicontrol('style','text',...
'units','pix',...
'position',[xCenter yCenter+20 FIELD_WIDTH FIELD_HEIGHT],...
'fontweight','bold',...
'string','PCA bool');
%% multiCondProjSpace
yCenter=yCenter-NEW_ROW_SHIFT;
menu.pca.multiCondProj=uicontrol('style','pop',...
'unit','pix',...
'position',[xCenter yCenter FIELD_WIDTH FIELD_HEIGHT],...
'string',[0,1],...
'Visible','off');
menu.pca.multiCondProjTitle=uicontrol('style','text',...
'units','pix',...
'position',[xCenter yCenter+20 FIELD_WIDTH FIELD_HEIGHT],...
'fontweight','bold',...
'string','multiCondProjSpace',...
'Visible','off');
%% threshold type
yCenter=yCenter-NEW_ROW_SHIFT;
menu.pca.threshType=uicontrol('style','pop',...
'unit','pix',...
'position',[xCenter yCenter FIELD_WIDTH FIELD_HEIGHT],...
'string',{'percent','rank'},...
'Callback', @dispThreshFields,...
'Visible','off');
menu.pca.threshTypeTitle=uicontrol('style','text',...
'units','pix',...
'position',[xCenter yCenter+20 FIELD_WIDTH FIELD_HEIGHT],...
'fontweight','bold',...
'string','threshold type',...
'Visible','off');
%% pcaPercs (100=off)
yCenter=yCenter-NEW_ROW_SHIFT;
menu.pca.percs=uicontrol(menu.FigH,'style','edit',...
'unit','pix',...
'position',[xCenter yCenter FIELD_WIDTH FIELD_HEIGHT],...
'string','[100]',...
'Visible','off');
menu.pca.percsTitle=uicontrol('style','text',...
'units','pix',...
'position',[xCenter yCenter+20 FIELD_WIDTH FIELD_HEIGHT],...
'fontweight','bold',...
'string','pcaPercs',...
'Visible','off');
%% pca rank
menu.pca.rank=uicontrol(menu.FigH,'style','edit',...
'unit','pix',...
'position',[xCenter yCenter FIELD_WIDTH FIELD_HEIGHT],...
'string','2',...
'Visible','off');
menu.pca.rankTitle=uicontrol('style','text',...
'units','pix',...
'position',[xCenter yCenter+20 FIELD_WIDTH FIELD_HEIGHT],...
'fontweight','bold',...
'string','rank',...
'Visible','off');
function dispPCAfields(hObject, eventdata, handles)
pcaBool=eval(hObject.String(hObject.Value));
%% pcaPercs-multiCondProjSpace
if pcaBool
%
set(menu.pca.multiCondProj,'Visible','on')
set(menu.pca.multiCondProjTitle,'Visible','on')
%
set(menu.pca.threshType,'Visible','on')
set(menu.pca.threshTypeTitle,'Visible','on')
%
set(menu.pca.percs,'Visible','on')
set(menu.pca.percsTitle,'Visible','on')
%
set(menu.pca.rank,'Visible','off')
set(menu.pca.rankTitle,'Visible','off')
else
%
set(menu.pca.multiCondProj,'Visible','off')
set(menu.pca.multiCondProjTitle,'Visible','off')
%
set(menu.pca.threshType,'Visible','off')
set(menu.pca.threshTypeTitle,'Visible','off')
%
set(menu.pca.percs,'Visible','off')
set(menu.pca.percsTitle,'Visible','off')
%
set(menu.pca.rank,'Visible','off')
set(menu.pca.rankTitle,'Visible','off')
end
end
function dispThreshFields(hObject, eventdata, handles)
threshType=hObject.String(hObject.Value);
if strcmp(threshType,'percent')
set(menu.pca.percs,'Visible','on')
set(menu.pca.percsTitle,'Visible','on')
%
set(menu.pca.rank,'Visible','off')
set(menu.pca.rankTitle,'Visible','off')
else
set(menu.pca.percs,'Visible','off')
set(menu.pca.percsTitle,'Visible','off')
%
set(menu.pca.rank,'Visible','on')
set(menu.pca.rankTitle,'Visible','on')
end
end
end
Adam Danz
Adam Danz 2019년 8월 1일
Any way you could attach all necessary files so we can run this and reproduce the problem? We'd need "addDataTypeFields", "addPCAFields", and anything else currently missing.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by