Change focus after tab selection in app designer

I'm workin in app designer, and have an app that has a tabgroup component with a corresponding selectionchanged callback function. I also have a windowskeypressfnc to allow hotkeys for specific buttons in the app once the tab is changed.
The issue I'm running into is that the hotkeys don't work after switching tabs (presumably because the focus is still on the tab). I've seen a few threads (e.g., here) on the issue of focus - but what I'm wondering is whether I can add a line of code to the selectionchanged callback function of the tab group to shift focus to the tab figure to allow the windowskeypressfnc to work appropriately? I've tried calling button functions and other attempts, but they don't seem to work.
Thinking something like:
function TabGroupSelectionChanged(app, event)
if strcmp(app.TabGroup.SelectedTab.Title,'specifictab')
end
%code to shift focus to something inside the tab to allow windowskeypressfcn to work.
%in GUIDE - UIcontrol would have done it.
else
end
end

11 Comments

Sorry for extra notifications.
drawnow;
figure(app.ApplicationUIFigure);
This works for me to get the focus back from uigetdir.
Nope. didn't work. Hotkeys still don't work right.
other suggestions?
Maybe you should put the code in the Window key press function.
My brain doesn't function well today :|
Tried that too - no dice.
Maybe a little more context could help:
For simplicity's sake, the app could be boiled down to 2 tabs (tab1 (default) and tab2), a button in tab 2 (that has an up arrow hotkey that activates its callback function) and a label. The value of the label goes up by 1 every time the button (or hotkey) is pressed.
When the app opens, you're on tab1. I click over to tab2, but the up arrow hotkey doesn't work until I click inside the tab space.
The plot thickens
I made a demo app that resembles the above scenario. The hotkey works perfectly. However, once I added a 2nd button to Tab1 (more similar to the true app I'm working with, where button in Tab1 must be pressed before switching tabs), then I get the same issue.
code attached.
Run the app, press the button in tab 1, switch tabs, and then press the "uparrow" key - nothing happens. Click in the tab2, press 'uparrow' key and value of the label increases by 1.
Thanks in advance!
This might be the case for staff.
Using the command to create a tab with the same name and parent tab group will create a duplicate tab, which is weird, because doing the same with figure, will just set the focus on it.
uitab(app.TabGroup, 'Title', 'Tab')
I guess that it has something to do with how uitab works.
Edit:
And after 5 mins, I found something. Well, It's not a visually great solution, but UI loses focus when you click on a button which is in Tab. If you place it outside, it will work (laughing).
Up through R2019b, there was no way to direct focus in uifigures .
If I recall correctly, R2020a added some limited facilities to direct focus. I do not recall the details at all, as I very rarely use App Designer.
Hi, I wonder, when you say that the focus is still on the tab if you can use the tab keybord button more than one? Cause I may have a similar issue. In my case, right when I press the tap button then the compueter seems to have lost the focus on the app itself, and I have to click anywhere on the app window to be able to get back control and use once again the tab key button and get the expected outcome!
I've found out to use the command 'focus(c)' and solves me a little more on my scope. On that comand 'c' stands for the uicontrol handle you want to keep the focus, which it'd be the "app.UITable". However, I have added a counter to increase the columns within the Key press function callback but it doesn't work, it seems as if the current object which is the app.UITable, keeps being on the original cell the one I clicked first, dispite the fact a 'tab' key is being press at least once. Anyone who knows how to solve?
Well, I have eventually solved, I'll quickly let it know here in case someone face the same issue like I was having. The reason is that you must increase the property 'Selection' one colum on yout app.UITable, which is what actually does the 'tab' key button on the keyboard on a well known software, and at the same time you must increase the property structure one columns as well (the porperty structure is a variable which I created to record the indices on the table cell selection and help to comunicate both callbacks, the callback to respond to any key press button and a callback which responds to cell selection). If you do like that it will work. Hope this helps anybody finds this. JesusChrist bless you all!

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 17 Sep 2020

Commented:

on 26 Oct 2023

Community Treasure Hunt

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

Start Hunting!