이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to activate drop down menus by clicking instead of hovering
조회 수: 5 (최근 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 (한국어)