Borrar filtros
Borrar filtros

App Designer get element in focus

27 visualizaciones (últimos 30 días)
ROL
ROL el 25 de En. de 2019
Respondida: Suraj Kumar el 30 de Jul. de 2024 a las 11:39
Hi there,
I switched from GUIDE to the App Designer some time ago, and find that a lot of important functionalities are now missing. One particular feature is the possibility to get a handle to the current GUI element in focus. In my particular example, I have 2 ListBox elements in my application and I want to add a shortcut to them for modification. The KeyPress function is only possible on the uifigure level, so I need a way to distinguish between the two ListBox elements.
Is this possible in some way or does this feature not exist at the moment.
Thanks, Rasmus
  2 comentarios
Quy
Quy el 18 de Feb. de 2020
Looking for an answer for this question as well.
Isak Idrizi
Isak Idrizi el 24 de Oct. de 2023
me too.

Iniciar sesión para comentar.

Respuestas (1)

Suraj Kumar
Suraj Kumar el 30 de Jul. de 2024 a las 11:39
Hi,
I understand that you are facing difficulty in getting the handle of the current GUI element which is in focus. As a workaround you can track the focus manually by setting up callbacks for each interactive component and storing the handle of the currently focused component in a property.
Consider adding a private property to store focussed component as shown below:
properties (Access = private)
FocusedComponent
end
Then implement the onKeyPress callback to handle key press events based on which ListBox is currently focussed.
You can refer to the code below for better understanding:
function onKeyPress(app, event)
if isempty(app.FocusedComponent)
return;
end
switch app.FocusedComponent
case app.ListBox1
% Handle key press for ListBox1
disp('Key pressed in ListBox1');
case app.ListBox2
% Handle key press for ListBox2
disp('Key pressed in ListBox2');
end
end
Please refer to the following documentation link on “callbacks” in App Designer :
Hope this helps!

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by