GUI Ignoring Changes to figure.Pointer Without a pause() command

3 ビュー (過去 30 日間)
AstroGuy1984
AstroGuy1984 2019 年 4 月 5 日
コメント済み: AstroGuy1984 2019 年 4 月 8 日
Hello, apologies if this has been answered before. I couldn't find a satisfactory issue like this, despite quite a few questions on changing the cursor.
I am building an app and at one button press a number of functions are taking place in the background. In lieu of making a waitbar, I just want the cursor to change the "watch" for the duration of the operation and back to "arrow" when done.
I know this is accomplished simply enough by changing the Figure property Pointer. Indeed, I do this by the following:
function buttonCallback(hObject, event)
figH = getappdata(hObject, 'parentFig');
% SOME CODE GETTING INPUTS FROM USER
figH.Pointer = 'watch';
% ANALYZING DATA CODE
figH.Pointer = 'arrow';
% Some cleanup code
end
The strange thing here is that this doesn't work. HOWEVER, it does work if I put a breakpoint in the line after I set the cursor to "watch". This gave the me the idea to put in a wait() command in such that:
figH.Pointer = 'watch'; pause(0.001);
This fixes the issue. Even stranger I don't have to put the wait in the resetting back to an arrow cursor.
This seems like a bit of a kludge to me, and I'd be curious as to what a better. or perhaps a more MATLAB-esque way to do this would be. Or, if it is correct, I'm confused as to why this is necessary. I have a different function that changes the mouse cursor depending on where it is in the app and that works perfectly great without a 'pause'.
Thank you for your time.
I am using 2018b, and I am NOT using GUIDE if that is relevant.

採用された回答

Kevin Phung
Kevin Phung 2019 年 4 月 5 日
add in a drawnow() command after you change the cursor.
  1 件のコメント
AstroGuy1984
AstroGuy1984 2019 年 4 月 8 日
That works just the same as the pause() comamnd did. Please help me understand what is going on. Because for some other functions in the GUI this was not needed, but here it is.
FAKE EDIT:
Ahhh reading the documentation on drawnow() I think I understand what's happening. The other calls to a cursor change I have are functions specifcally designed to check for user behavior and change the cursor accordingly. Those functions work and update the figure handles when executed.
The reason it's not working in this particular call where I want it is because it's executing other code (and not the larger figure stuff) until it's already changed it back.
drawnow() is a function I've only ever considered for children of axes.
Thanks, I also put this explanation in in case someone else had the same confusion.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by