How to deselect ToolbarStateButton without clicking on it?
Afficher commentaires plus anciens
I have a GUI in GUIDE and I would like to deselect any ToolbarStateButton currently selected for an axes any time another button is pressed. I'm hitting dead ends. Is it possible to modify the ValueChangedFunction?
For example I click the zoom button on the axis and then I press Button1, I want to disable zoom button and change the mouse back to it's normal state (not zooming in with the crosshairs).
Deleting the toolbar does not set the mouse back to it's normal state.
Setting the Value parameter to off deselects the button on the toolbar but does not change the mouse back to it's normal non-zooming state.
Any advice would be appreciated.
UPDATE - SOLUTION: Create custom toolbar to allow access to Toolbar Children. Set all of the values to 'off', use datacursormode to turn tooltip on and then off. See below.
If anyone has a better solution please let me know.
% Non default toolbar allows access to Toolbar Children
handles.TB1 = axestoolbar(handles.Axes1,'default');
handles.TB1.Visible = 'on';
for i = 5:6 % Turn zoom buttons off
handles.TB1.Children(i).Value = 'off'
end
% Reset data cursor
datacursormode(handles.figure1,'on')
datacursormode(handles.figure1,'off')
Réponse acceptée
Plus de réponses (1)
Charles Mercier
le 30 Jan 2020
My approach is similar to yours, but relies on the builtin functions used by Matlab for the toolbar buttons, which makes it a bit more versatile. For instance, the following code will deselect any state button with the proper callback (for exemple the rotation button in a 3D plot as well). On a sidenote, I agree that this was an annoyance to begin with and that Matlab should include an easier way to control toolbar's interactions.
% Properly deselects any state button in the toolbar
handles.TB1 = axtoolbar(handles.Axes1,'default');
handles.TB1.Visible = 'on';
for k = 1:numel(handles.TB1.Children)
if isa(handles.TB1.Children(k),'matlab.ui.controls.ToolbarStateButton')
if strcmp(handles.TB1.Children(k).Value,'on')
e = handles.TB1.Children(k);
d = struct;
d.Source = e;
d.Axes = handles.Axes1;
d.EvenName = 'ValueChanged';
d.Value = 'off';
d.PreviousValue = 'on';
feval(handles.TB1.Children(k).ValueChangedFcn,e,d);
end
end
end
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!