How I make a pushbutton invisible in a GUI?
24 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I has a picture of a drumset/percussion and wants to click a drum which then makes a sound. So I wants a button on my drum, but invisible. So I can still see the drum on my window figure without pushbutton.
My Script:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[s,fs]=wavread('filename.wav');
sound(s,fs);
Thankyou..
0 commentaires
Réponses (2)
Stephen23
le 23 Sep 2016
Modifié(e) : Stephen23
le 23 Sep 2016
Setting the Visible property to off will not work, because then the uicontrol does not respond to clicking.
Here are two alternatives that actually work, but are perhaps not as beautiful as an invisible, clickable button.
Button on top of an image
X = imread('drum.jpg');
fgh = figure('Color','white');
image(X)
axis off
axis image
uih = uicontrol(fgh,'Style','pushbutton', 'BackGroundColor','white',...
'Units','normalized','Position',[0.5,0.4,0.2,0.2], 'String','press',...
'Callback',@(h,e)disp('bang!'));
Button displaying an image
X = imread('drum.jpg');
fgh = figure('Color','white');
uih = uicontrol(fgh,'Style','pushbutton', 'BackGroundColor','white',...
'Units','pixels', 'Position',[20,20,200,200], 'String','press',...
'CData',X, 'Callback',@(h,e)disp('bang!'));
Both methods use this image:
6 commentaires
Stephen23
le 23 Sep 2016
Modifié(e) : Stephen23
le 21 Mar 2018
I don't see any simple solution that makes the button invisible. So far I have shown you:
- making button invisible: does not work.
- button on top of image: works.
- button contains image: works.
One more option would be to write your own "button" by defining a callback that detects the mouse position and decides how to respond based on its position. For this you will have to start by reading these:
then you will have to use some kind of indexing to specify the required location, and define a callback function that uses this to trigger your code.
Amanda Irving
le 8 Août 2019
Starting in R2019a, there is a new component available called uiimage.
You can assign an image using the ImageSource property and assign a callback using the ImageClickedFcn:
0 commentaires
Voir également
Catégories
En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!