Is there a way of identifying a ui-component object when it acquires focus?

18 vues (au cours des 30 derniers jours)
Amos
Amos le 20 Oct 2022
I have an array of custom ui components, each of which contains a number of standard ui component objects.
I am attempting to identify the parent element (in the array) when one of it's components takes the focus.
I note the ButtonDownFcn callback doesn't appear to be universally available.

Réponses (1)

Piyush Dubey
Piyush Dubey le 4 Sep 2023
Hi Amos,
In my understanding, you have an array of custom UI components where these components are composed of standard UI objects. You want to determine the parent UI component of the standard UI object which is currently in focus. Also, the ButtonDownFcn callback is not being accessed universally.
To obtain the parent of a child object, the child object’s handle is fetched. The currently focused UI object’s handle can be temporarily disabled, doing this makes uicontrol point to the parent of the standard child object which was in focus then.
Please refer to the following MATLAB Answer’s thread where similar issues were resolved:
Please know that "ButtonDownFcn" callback is only executed when you click on the standard child component objects itself. If you want the "ButtonDownFcn" callback function to be executed regardless of where you click in the UI component, try the following:
  • Set the "HitTest" property for the custom parent and children objects to 'off'. The "HitTest" property determines whether the object can become the current object when it is clicked on.
Please refer to the following MathWorks documentation link to learn more about “HitTest:
  • Specify the desired callback function as the figure's "WindowButtonDownFcn" property. The "WindowButtonDownFcn" callback is executed whenever you click in the figure and is executed before the "ButtonDownFcn" callback of any objects, including the figure itself.
You may refer to this MATLAB Answer’s thread for a similar discrepancy that a user had faced:
  • Define the "ButtonDownFcn" callbacks for the child objects, so they have the same effect as calling the parent UI component’s "ButtonDownFcn" callback. This may include determining the object's Parent and passing its handle as an input instead of the object's handle.
Hope this helps!

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by