Trouble with ButtonDownFcn and Hittest in GUIDE

3 ビュー (過去 30 日間)
Michael
Michael 2011 年 6 月 3 日
Hi All,
I'm making my first GUI and am having trouble with the ButtonDownFcn for a set of axes. I've read that others have had trouble with a similar situation and that the solution was to set the Hittest on all the objects on top of the axes to 'off.' I'm not sure what I'm doing wrong. I've made a cartoon version of my code that recreates the same problem without all the extra functions of my actual GUI. In my code I plot some data "ThePlot" on my axes "TheAxes" and once I do the ButtonDownFcn ceases to work. If I comment out the plot the ButtonDownFcn does work (in this instance it just changes some text). Thanks in advance for the help. The code is as follows:
% --- Executes just before FigureWindow is made visible.
function FigureWindow_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figureff
% 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 FigureWindow (see VARARGIN)
xvalues = linspace(0,10,1000);
yvalues = sin(xvalues) + sqrt(xvalues);
TheAxes = handles.TheAxes;
ThePlot = plot(TheAxes,xvalues,yvalues,'tag','ThePlotTag');
set(ThePlot,'Hittest','off');
% Choose default command line output for FigureWindow
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes FigureWindow wait for user response (see UIRESUME)
% uiwait(handles.FigureWindow);
% --- Executes on mouse press over theaxes background.
function TheAxes_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to TheAxes (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
TheText = handles.TheText;
set(TheText,'String','You clicked on the Axes');

採用された回答

Jonas Reber
Jonas Reber 2011 年 6 月 3 日
this looks reasonable to me. have you tried
ThePlot = plot(xvalues, yvalues, 'Parent', handles.TheAxes, 'Tag', 'ThePlotTag', 'HitTest', 'off', 'ButtonDownFcn', '');
? or you might want to use a simple line instead of the high-level function plot:
ThePlot = line('Parent', handles.TheAxes, 'XData', xvalues, 'YData', yvalues);
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 6 月 3 日
The shorter version of that last line is
ThePlot = line(handles.TheAxes, xvalues, yvalues);
Jonas's version is correct; this version is an abbreviation.

サインインしてコメントする。

その他の回答 (1 件)

Michael
Michael 2011 年 6 月 3 日
Thank you Jonas and Walter. Using 'line' is definitely the right way to go. I really appreciate your help!

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by