SelectionType of Mousebutton is empty

Hello!
For context: i'm a beginner and want to design an app in Matlabs App Designer where the user needs to click on a small image in the apps window (which is otherwise empty). There needs to be two different actions weather the right or left mousebutton is pushed. With the right mousebutton there should'nt be any difference weather the mouse is positioned above the image or not.
I found several solutions that use 'get' to get the 'SelectionType' in the function WindowButtonDownFcn. However in my case whatever i push wherever i am, the resulting variable 'clickType' is instead of 'alt' or 'normal' just an empty 0x0 double value. What am i doing wrong? Is there a way i can just add a different callback function for the right mouseclick? Or is there maybe a more elegant way to approach this?
Thanks in advance!
function WindowButtonDownFcn(app, event)
figHandle = ancestor(app, 'figure');
clickType = get(figHandle, 'SelectionType');
if strcmp(clickType, 'alt')
% Do something for right Mouseclick
else
% Do something else
end
end

 Respuesta aceptada

Steven Lord
Steven Lord el 1 de Oct. de 2021

0 votos

Likely your figHandle variable is empty. If you're looking to determine how the mouse button was pressed in your app window why not ask your app window (whose handle is app) what its SelectionType property value is?

4 comentarios

Barbara Kammerl
Barbara Kammerl el 1 de Oct. de 2021
If i change 'figHandle' in line 3 to 'app' and erase line 2, then i get an error stating that Matlab couldn't find the method 'get'.
Sorry, I typed that first message on my phone and so didn't type as much as I perhaps should have. I'm not sure the get approach for retrieving properties is defined for uifigure objects. Try:
clickType = app.SelectionType;
If that doesn't work, can you show us the output of this command? Add it as the first line in that function and reproduce the error.
whos app
It immediatly produces the error message "Unrecognized method, property or field 'SelectionType' for class 'Name_of_app'.
the output of
whos app
gets me this: (sorry if thats not what you ment by it)
After a bit of trying i found a solution that works.
clickType = get(event.Source).SelectionType;
gives back the correct value of 'alt' when using the right mouse button. Sadly this only works outside of the image. The image itself can apparently only be clicked on with the left mouse button (won't go into the callback function when right-clicked). Should i open up a new question for this, or is there maybe an easy and quick fix? Thank you for your time!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Preguntada:

el 1 de Oct. de 2021

Comentada:

el 1 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by