Clicking a button in a UIFigure that is not in focus only brings it the figure into focus, clicking it again causes the button action to happen twice.

5 visualizaciones (últimos 30 días)
I have two interacting UIFigures. When the user clicks on a button in the figure that is not in focus, nothing happens other than the focus changing. Typically, the user clicks the button again, but when they do the ButtonPushedFcn runs twice. It is possible to get around this by clicking dead space in the figure before clicking the button, or by clicking dead space in the figure after recognizing that the first click (the one that changed focus) had no effect. The second work-around is interesting because <button click--dead space click--button click> on an off-focus figure only runs the button function once, but if you leave out the dead space click it runs twice. The behavior is the same whether the button function calls external functions, functions in the other figure, or functions button's figure.

Respuesta aceptada

William Gray
William Gray el 20 de Dic. de 2021
From Mathworks Support:
Hello William,
This behavior is expected with Mac computers. The Mac operating system will interpret the first click on an inactive window purely as a focus shift, but in the case of a double click, both clicks will be registered as actual clicks.
To verify this behavior, please do the following:
1) Open up a browser, such as Google Chrome. Create two windows of it.
2) On one window, go to a website that counts the number of clicks you make (such as https://www.rapidtables.com/tools/click-counter.html).
3) Focus on the non-clicker window.
4) Double click on the clicker in the non-focused window. You will see that the counter goes up by 2.
5) If you do steps 3 and 4 again, but only click once on the clicker in the non-focused window, you will see that the counter remains the same.
I will go ahead and close this case. If you have any additional questions related to this case, please reply to this email and I will be happy to reopen the case and assist you further.
Sincerely,
Bryan Acosta
MathWorks Technical Support Department
Follow up: Bryan said in a follow-up response, "Since this behavior is a limitation with the Mac operating system, there is unfortunately no workaround for this issue."

Más respuestas (1)

Adam Danz
Adam Danz el 10 de Dic. de 2021
Editada: Adam Danz el 10 de Dic. de 2021
> I have two interacting UIFigures. When the user clicks on a button in the figure that is not in focus, nothing happens other than the focus changing.
This shouldn't be the case. I tested the behavior using the very simple example below which produces two uifigures each with a button that merely displays a message in the command window.
fig1 = uifigure();
but1 = uibutton(fig1,"ButtonPushedFcn",@(~,~)disp('b1 pressed'));
fig2 = uifigure();
but2 = uibutton(fig2,"ButtonPushedFcn",@(~,~)disp('b2 pressed'));
> Typically, the user clicks the button again, but when they do the ButtonPushedFcn runs twice.
It sounds like something is delaying the callback function on the first press or it's queued and then the second press is executing the que.
The first thing I would try is to determine whether this problem happens with the simple demo I provided above. If it does occur, restart Matlab in case it's just a fluke. If the problem doesn't occur with the simple demo but does occur with your uifigures, then we know the problem is isolated and may be caused by lots of different issues (an interaction between events, listeners, figure settings changing, something within the callback function, who knows.....). In that case, perhaps you could attach the two uifigures and describe how to recreate the problem.
  3 comentarios
Adam Danz
Adam Danz el 10 de Dic. de 2021
I've tested the simple demo in R2021a (Windows) and I don't get the behavior you're describing. You may want to contact tech support

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by