Hittest axes with WindowWheelScrollFcn callback

조회 수: 6 (최근 30일)
Bjarke Skogstad Larsen
Bjarke Skogstad Larsen 2018년 6월 29일
댓글: Bjarke Skogstad Larsen 2018년 6월 29일
I am attempting to make a GUI that has interaction using the mouse wheel, and the GUI behavior should depend on which element the mouse cursor is over when the mouse wheel is used. There are multiple axes objects, and I have previously (probably around 2012) used hittest to check which axes the mouse cursor was hovering over. However, this no longer works unless I first use mouse click on the axes.
It seems like an odd behavior imo. Is there any way to achieve what I want without having to click on the axes first?
  댓글 수: 1
Bjarke Skogstad Larsen
Bjarke Skogstad Larsen 2018년 6월 29일
Example code:
function pickHit2
f = figure;
ax = axes;
p1 = patch(rand(1,3),rand(1,3),'r');
p2 = patch(rand(1,3),rand(1,3),'b');
set(f,'WindowScrollWheelFcn',@hitresult);
function hitresult(obj,event)
hObj = hittest(obj);
switch hObj
case f
disp('Figure');
case ax
disp('Axes');
case p1
disp('Patch (Red)');
case p2
disp('Patch (Blue)');
end
end
end

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 6월 29일
  댓글 수: 2
Bjarke Skogstad Larsen
Bjarke Skogstad Larsen 2018년 6월 29일
Thank you for your answer. This does seem to work as I intended but only when the axes are direct children of the figure. Unfortunately, the GUI I'm designing uses panels to tab between views, so it won't work for it :-(
Example code to show the problem:
function pickHit3
f = figure;
p = uipanel(f);
ax1 = axes(p,'Position',[0.1 0.1 0.3 0.8]);
ax2 = axes(p,'Position',[0.6 0.1 0.3 0.8]);
set(f,'WindowScrollWheelFcn',@hitresult);
function hitresult(obj,event)
hObj = overobj('axes');
if ~isempty(hObj)
switch hObj
case ax1
disp('Axes (Left)');
case ax2
disp('Axes (Right)');
end
else
disp('No Axes under cursor');
end
end
end
Bjarke Skogstad Larsen
Bjarke Skogstad Larsen 2018년 6월 29일
Sorry, I missed the "2" :-) It works with the modified version supplied by your link, thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by