How to focus on 'edit text' callback by WindowKeyPressFcn in GUIDE.
조회 수: 1 (최근 30일)
이전 댓글 표시
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'?
댓글 수: 0
채택된 답변
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 Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!