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!