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!