You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to activate drop down menus by clicking instead of hovering
5 views (last 30 days)
Show older comments
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 Comments
Geoff Hayes
on 7 Sep 2015
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
on 7 Sep 2015
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
on 7 Sep 2015
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
on 7 Sep 2015
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
on 7 Sep 2015
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
on 8 Sep 2015
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
Answers (0)
See Also
Categories
Find more on Install Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)