How I make a pushbutton invisible in a GUI?

14 visualizzazioni (ultimi 30 giorni)
sibolis naburju.id
sibolis naburju.id il 23 Set 2016
Risposto: Amanda Irving il 8 Ago 2019
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..

Risposte (2)

Stephen23
Stephen23 il 23 Set 2016
Modificato: Stephen23 il 23 Set 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 Commenti
Stephen23
Stephen23 il 23 Set 2016
Modificato: Stephen23 il 21 Mar 2018
I don't see any simple solution that makes the button invisible. So far I have shown you:
  1. making button invisible: does not work.
  2. button on top of image: works.
  3. 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.
Stephen23
Stephen23 il 23 Set 2016
Modificato: Stephen23 il 21 Mar 2018
"How i do that?" I showed you already. This is the second method in my answer. I even tested it and showed you a screenshot.

Accedi per commentare.


Amanda Irving
Amanda Irving il 8 Ago 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:

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by