GUI: function to change pushbutton color on mouseover
19 ビュー (過去 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!