Zoom in using mouse scroll during uiwait sometimes fails

4 ビュー (過去 30 日間)
Xingwang Yong
Xingwang Yong 2021 年 12 月 17 日
コメント済み: Xingwang Yong 2021 年 12 月 17 日
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 Center および File ExchangeInteractive 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