Zoom in using mouse scroll during uiwait sometimes fails
4 次查看(过去 30 天)
显示 更早的评论
I want to zoom in a figure (with mouse scroll) during uiwait, however this did not always work.
If you directly run main.m, you'll find out you can not zoom in with mouse scroll.
However, if you comment test_zoomin(gcf), and run again, then move your mouse into figure, at last run test_zoomin(gcf) in command window, you'll find out you can zoom in with mouse scroll.
The above is well reproduced on my win10 with R2020a and R2021a. Also, I tried to use set(0, 'PointerLocation', ...) to programtically move mouse into figure before calling test_zoomin(), while it still did not work as intended.
Why zoom in with mouse scroll behaves so differently?
PS. Zoom in with the icon '+' on upper right of figure always work.
%% main.m
close all;
img = imread('pout.tif');
figure('Position',[1277 731 414 384]);imshow(img);
test_zoomin(gcf);
%% test_zoomin.m
function test_zoomin(h_fig)
if nargin < 1
h_fig = gcf;
end
figure(h_fig);
Button = uicontrol('Parent',h_fig,'Style','pushbutton','String',...
'OK','Units','normalized','Position',[0.95 0.90 0.05 0.05],'Visible','on',...
'Tag', 'OKPushbutton', 'Callback', @pushbtn_callback);
uiwait; % wait until user click 'OK'
end
function pushbtn_callback(src, event)
uiresume(); %Resume execution of blocked program
end
0 个评论
采纳的回答
yanqi liu
2021-12-17
may be the mouse zoom is default
%% main.m
close all; clc; clear all;
img = imread('pout.tif');
hfig=figure('Units','normalized','Position',[0.05 0.05 0.85 0.85]);
imshow(img);
ax = gca;
ax.Interactions = [zoomInteraction];
disableDefaultInteractivity(ax)
test_zoomin(hfig);
%% test_zoomin.m
function test_zoomin(h_fig)
if nargin < 1
h_fig = gcf;
end
figure(h_fig);
ax = gca;
ax.Interactions = [zoomInteraction];
enableDefaultInteractivity(ax)
Button = uicontrol('Parent',h_fig,'Style','pushbutton','String',...
'OK','Units','normalized','Position',[0.90 0.50 0.05 0.05],'Visible','on',...
'Tag', 'OKPushbutton', 'Callback', @pushbtn_callback);
uiwait; % wait until user click 'OK'
end
function pushbtn_callback(src, event)
uiresume(); %Resume execution of blocked program
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!