フィルターのクリア

How to focus on 'edit text' callback by WindowKeyPressFcn in GUIDE.

3 ビュー (過去 30 日間)
Ali Y.
Ali Y. 2016 年 6 月 23 日
コメント済み: Ali Y. 2016 年 6 月 23 日
I have a gui that includes an 'edit text' callback (queryet_1).
function queryet_1_Callback(hObject, eventdata, handles)
% hObject handle to queryet_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of queryet_1 as text
% str2double(get(hObject,'String')) returns contents of queryet_1 as a double
input = get(hObject,'String');
To add a keyboard shortcut I use the following code.
function figure1_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
k = eventdata.Key;
if strcmp(k,'f2')
queryet_1_Callback(hObject, eventdata, handles)
end
However, it gives the following error, refering to the line “input = get(hObject,'String');”
Error using hg.figure/get
The name 'String' is not an accessible property for an instance of class 'figure'.
My questions is why WindowKeyPressFcn does not work for 'edit text' callback while it deos for others like 'bushbottun'?

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 6 月 23 日
Ali - look at how you are calling queryet_1_Callback from within the figure1_WindowKeyPressFcn function
if strcmp(k,'f2')
queryet_1_Callback(hObject, eventdata, handles)
end
In the above, hObject is the handle to figure1 and not the queryet_1 text box. hObject always refers to the handle to the "source" of the callback (so the control that the callback is assigned to). Instead, pass the handle to the queryet_1 as
if strcmp(k,'f2')
queryet_1_Callback(handles.queryet_1, eventdata, handles)
end
Try the above and see what happens!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by