How to activate drop down menus by clicking instead of hovering
4 次查看(过去 30 天)
显示 更早的评论
John
2015-9-7
Hi guys,
i just started creating a complex GUI and i am not that experienced yet. What i would like to have is a menu bar that contains dropdown menus as well as simple buttons... So for example the Tab 'Model' consists of a dropdown menue whereas the Tab 'Help' doesnt offer any other options. So Clicking help should immediately activate a callback whereas clicking 'Model' shall open the dropdown menu for further choices to be made...how can i realize this??? so far i created this Surface below with the GUIDE environment that automatically implements hovering over the tabs insteand of clicking...
I would be very glad for your help:) Best regards, John
6 个评论
Geoff Hayes
2015-9-7
John - it isn't clear to me what you mean by hovering over the menu items. Do you mean that when you hover over a menu item, the item list automatically expands? I am using R2014a and when I move the mouse over one of the menu items, I have to click it in order to expand the menu item list. If I have just a single Help menu item (with no sub-items) then pressing Help would fire the callback associated with this menu.
When you create the menu items, don't you see callbacks for each being added to your m file? What version of MATLAB are you using?
John
2015-9-7
Hi Geoff,
i use MATLAB R2013b. Yes thats what i am talking about. As soon as i once clicked in the area of the toolbar, every item is immediately acitvated just by hovering over the menu items. the pop ups extend automatically without clicking and the execution of the callback functions behind the menu items is executed automatically as well....here is my code for that...i created it with GUI..
function varargout = Try1(varargin)
% TRY1 MATLAB code for Try1.fig
% TRY1, by itself, creates a new TRY1 or raises the existing
% singleton*.
%
% H = TRY1 returns the handle to a new TRY1 or the handle to
% the existing singleton*.
%
% TRY1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TRY1.M with the given input arguments.
%
% TRY1('Property','Value',...) creates a new TRY1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Try1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Try1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Try1
% Last Modified by GUIDE v2.5 07-Sep-2015 14:37:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Try1_OpeningFcn, ...
'gui_OutputFcn', @Try1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Try1 is made visible.
function Try1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Try1 (see VARARGIN)
% Choose default command line output for Try1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Try1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Try1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
function model__Callback(hObject, eventdata, handles)
% hObject handle to model_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model')
% --------------------------------------------------------------------
function library__Callback(hObject, eventdata, handles)
% hObject handle to library_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('library')
% --------------------------------------------------------------------
function settings__Callback(hObject, eventdata, handles)
% hObject handle to settings_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('settings')
Try1_subgui
% --------------------------------------------------------------------
function results__Callback(hObject, eventdata, handles)
% hObject handle to results_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('results')
% --------------------------------------------------------------------
function dataformat__Callback(hObject, eventdata, handles)
% hObject handle to dataformat_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('dataformat')
% --------------------------------------------------------------------
function about__Callback(hObject, eventdata, handles)
% hObject handle to about_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('about')
% --------------------------------------------------------------------
function help__Callback(hObject, eventdata, handles)
% hObject handle to help_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('help')
% --------------------------------------------------------------------
function license__Callback(hObject, eventdata, handles)
% hObject handle to license_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('about---lincense')
% --------------------------------------------------------------------
function site__Callback(hObject, eventdata, handles)
% hObject handle to site_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('about---site')
% --------------------------------------------------------------------
function opendssforum__Callback(hObject, eventdata, handles)
% hObject handle to opendssforum_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('about---opendssforum')
% --------------------------------------------------------------------
function lan__Callback(hObject, eventdata, handles)
% hObject handle to lan_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('about---lan')
% --------------------------------------------------------------------
function save__Callback(hObject, eventdata, handles)
% hObject handle to save_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('results---save')
% --------------------------------------------------------------------
function load__Callback(hObject, eventdata, handles)
% hObject handle to load_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('results---load')
% --------------------------------------------------------------------
function new__Callback(hObject, eventdata, handles)
% hObject handle to new_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---new')
% --------------------------------------------------------------------
function edit__Callback(hObject, eventdata, handles)
% hObject handle to edit_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---edit')
% --------------------------------------------------------------------
function samples__Callback(hObject, eventdata, handles)
% hObject handle to samples_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---samples')
% --------------------------------------------------------------------
function sample1__Callback(hObject, eventdata, handles)
% hObject handle to sample1_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---samples---sample1')
% --------------------------------------------------------------------
function sample2__Callback(hObject, eventdata, handles)
% hObject handle to sample2_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---samples---sample2')
% --------------------------------------------------------------------
function sample3__Callback(hObject, eventdata, handles)
% hObject handle to sample3_ (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('model---samples---sample3')
The disp-commands are only implemented for testpurposes so to know that the callback works...so my matlab command-window showsfor example this sequence after hovering over the items:
help
about
dataformat
results
settings
help
about
dataformat
help
model
model---samples
library
model
model---samples
library
settings
help
about
dataformat
results
settings
You got my problem? i want the callbacks to be activated by clicking:D
Geoff Hayes
2015-9-7
Hi John - that is an interesting problem that still exists in R2014a. I'm not sure if the behaviour makes sense or not. It definitely doesn't seem consistent as the callbacks for the sub-menus don't fire unless you physically click on them (hovering doesn't seem to cause the callback to fire in this case).
John
2015-9-7
Hi Geroff, indeed, didnt pay attention to this...its only the parent items that fire directly...really strange! Is this maybe due to using the GUIDE environment?!...maybe one can avoid this situation by programming the GUI from the bottom although i would not appreciate that since GUIDE is much easier!
Image Analyst
2015-9-7
You forgot to attach your .fig and .m files with the paper clip icon. As of now, no one can try anything with your code.
John
2015-9-8
Hi Image Analyst,
so here is my hole GUI attached. It works nice apart from the fact that the menu does behave as described above! i dont know how to solve this issue..would be quite important to have a functioning menu somehow... the Try1_subgui.m ist a GUI that is called when the menu-button settings in Try1.m is activated. It is just the basic so far because i just startet with getting familiar with GUI.
However, every menu that i create with GUIDE behaves this way...this is definately not intended!! i dont know how to fix it or what other options i do have to create a functioning menu-bar.
Best regards, john
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)