GUI: function to change pushbutton color on mouseover
조회 수: 21 (최근 30일)
이전 댓글 표시
Hi, I'm trying to create a simple GUI. I want to make the uicontrol pushbuttons to change a specific color when mouse over. I've been trying to find the answer on the forum but with no success. Please help me as without this I can't move on with my work (it's one of the requirements of the project). Here is the code I have so far:
function fig = mainmenu()
col = [0.0 0.2 0.4];
h0 = figure(...
'Color',[0.95 0.95 0.95], ...
'PaperPosition',[18 180 576 432], ...
'PaperUnits','points', ...
'Units','normalized',...
'Position',[0.72 0.55 0.21 0.4], ...
'NumberTitle','off',...
'Name','Software X', ...
'MenuBar','none', ...
'Resize','off',...
'ToolBar','none');
hp = uipanel(...
'Title','Analysis',...
'TitlePosition', 'centertop',...
'Position',[.05 .05 .9 .9],...
'FontUnits','normalized',...
'ForegroundColor',[0.0 0.2 0.4],...
'FontSize',0.065);
h1 = uicontrol('Parent',hp, ...
'Units','norm', ...
'Position',[0.15 0.65 0.7 0.11], ...
'FontUnits','normalized',...
'Fontsize',0.4,...
'BackgroundColor',col, ...
'ForegroundColor',[1 1 1],...
'Style', 'pushbutton',...
'String','Link 1', ...
'CallBack','link to another menu;');
h2 = uicontrol('Parent',hp, ...
'Units','norm', ...
'Position',[0.15 0.5 0.7 0.11], ...
'FontUnits','normalized',...
'Fontsize',0.4,...
'BackgroundColor',col, ...
'ForegroundColor',[1 1 1],...
'String','Link 2', ...
'Style','pushbutton',...
'CallBack','link to another menu;');
h3 = uicontrol('Parent',hp, ...
'Units','norm', ...
'Position',[0.15 0.35 0.7 0.11], ...
'FontUnits','normalized',...
'Fontsize',0.4,....
'BackgroundColor',col, ...
'ForegroundColor',[1 1 1],...
'String','Close',...
'CallBack','delete(gcf)');
if nargout > 0, fig = h0; end
댓글 수: 0
답변 (1개)
David Barry
2016년 8월 25일
You should take a look at the WindowButtonMotionFcn callback property on the Figure. You could use this to define your own custom callback function which gets the current mouse position, checks if it coincides with the position of your button and responds accordingly.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!