Matlab main window is called when selecting file

조회 수: 6 (최근 30일)
Ahmed
Ahmed 2023년 12월 1일
댓글: Rik 2023년 12월 12일
I am designing an app and I am currently using the follow line of code to get the user to select a file from their device, however once the file is selected by the user, the matlab main window if brought to the forefront of the screen and I wouldnt like that:
[file, path] = uigetfile('*.stl', 'Select STL File'); % Open the file dialog
  댓글 수: 2
Rik
Rik 2023년 12월 2일
The code you posted should not cause the main Matlab window to steal focus.
Is this only happening in the context of AppDesigner?
Ahmed
Ahmed 2023년 12월 2일
Yes, once the file is selected the main MATLAB window will come up and the app is behind the main MATLAB window

댓글을 달려면 로그인하십시오.

답변 (1개)

Karanjot
Karanjot 2023년 12월 12일
편집: Karanjot 2023년 12월 12일
Hi Ahmed, I understand that your MATLAB App Designer application loses focus after the function 'uigetfile' returns.
This seems to be a known issue with App Designer. I recommend the following workaround suggested by Onur Ozdemir to prevent 'uigetfile' from sending the MATLAB App Designer window to background
f = figure('Renderer', 'painters', 'Position', [-100 -100 0 0]); %create a dummy figure so that uigetfile doesn't minimize our GUI
[filename,path] = uigetfile('*.txt', 'Open text file','MultiSelect','on');
delete(f); %delete the dummy figure
To learn more about the workaround, you may refer to the webpage below:
I hope this helps!
  댓글 수: 1
Rik
Rik 2023년 12월 12일
Be careful with these magic numbers. A figure window of 0x0 units might trigger warnings. The position 100 units below and left of the lower left corner of the monitor might also be an issue in edge cases: this is in reference to the main monitor. In a multi-monitor setup this could cause problems. Apart from the fact that some OSes don't like it if you try to put a window outside of the visibile area.
But these should all be edge cases.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by