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

采纳的回答

yanqi liu
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
  1 个评论
Xingwang Yong
Xingwang Yong 2021-12-17
It seems that uiwait changes default interactivity if the mouse did not move into figure at the beginning. Anyway, thank you very much!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by