[英]matlab using SizeChangedFcn doesn't call function using guide
我想實現一些代碼,以便當用戶調整窗口大小時可以調用一個函數。 我正在使用matlab 2018,他們建議使用SizeChangedFcn而不是ResizeFcn。 我並沒有過多地處理回調,但是我很難讓我的GUI每次調整窗口大小時都調用SizeChangedFcn。 Currenlty,根本沒有調用該函數。
function varargout = firstgui(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @firstgui_OpeningFcn, ...
'gui_OutputFcn', @firstgui_OutputFcn, ...
'SizeChangedFcn', @resizeui, ... % <-- added this line
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function resizeui(hObject,event)
disp("Hi");
編輯:
我應該提到的是,我使用的程序嚴重依賴於指南,因此我堅持使用該實現。
這是“ gui_mainfcn”中的內容
function varargout = gui_mainfcn(gui_State, varargin)
% GUI_MAINFCN Support function for creation and callback dispatch of GUIDE GUIs.
% GUI_MAINFCN is called from inside MATLAB code files generated by GUIDE to handle
% GUI creation, layout, and callback dispatch.
%
% See also: GUIDE.
% GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs
% are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
% Copyright 1984-2015 The MathWorks, Inc.
gui_StateFields = {'gui_Name'
'gui_Singleton'
'gui_OpeningFcn'
'gui_OutputFcn'
'SizeChangedFcn' %added this line as well does not work yet
'gui_LayoutFcn'
'gui_Callback'};
我在這里找到解決方案:
https://www.mathworks.com/help/matlab/creating_guis/gui-options.html
通過選擇“工具”>“ GUI選項”,從GUIDE布局編輯器訪問對話框。
其他(使用SizeChangedFcn)-對UI進行編程,以在用戶調整圖形窗口的大小時以某種方式運行。
在gui選項中選擇“ SizeChangedFcn”時,它為我創建了一個函數。
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp("Hi");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.