GUI: function to change pushbutton color on mouseover
20 次查看(过去 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!