Why does the delete key increase the opacity of an ellipse?
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
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
댓글 수: 0
답변 (1개)
  Kanishk
 2025년 1월 20일
        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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

