Why does the delete key increase the opacity of an ellipse?

2 Ansichten (letzte 30 Tage)
Joseph Henry
Joseph Henry am 16 Jul. 2019
Beantwortet: Kanishk am 20 Jan. 2025
Hi,
I have an App Designer GUI that draws elliptical ROIS on images. I just made a callback that deletes the currently selected ROI by pressing the 'delete' key. The function works fine, but if 'delete' is pressed more than once, the remaining ellipses' opacity increases with each press.
Why is this happening, and is there any way to prevent this?
Thanks

Antworten (1)

Kanishk
Kanishk am 20 Jan. 2025
I tried reproducing the issue in MATLAB R2024b with App Designer and ROI using “drawcircle”. However, I was not able to reproduce the issue. I used the “KeyPressFcn” callback for the “UIFigure” of the app to detect the delete key press and identified the ROI to be deleted using the “Selected” Property.
Here are the callback functions and I am also attaching the “mlapp” file for the app.
function UIFigureKeyPress(app, event)
if strcmp(event.Key, 'delete') && ~isempty(app.ROIs)
% Iterate over the ROI array to find the selected one
for i = 1:length(app.ROIs)
if app.ROIs(i).Selected
delete(app.ROIs(i)); % Delete the selected ROI
app.ROIs(i) = []; % Remove it from the array
app.ROIs
break; % Exit the loop after deleting
end
end
end
end
Add the callback function to the UIFigure.
app.UIFigure.KeyPressFcn = createCallbackFcn(app, @UIFigureKeyPress, true);
To learn more about "drawcircle" and "createCallbackFcn", Please use this command to access the official MathWorks documentation.
web(fullfile(docroot, 'images/ref/drawcircle.html'))
web(fullfile(docroot, 'matlab/creating_guis/write-callbacks-for-apps-created-programmatically.html'))
Hope that helps!

Community Treasure Hunt

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

Start Hunting!

Translated by