Get mouse down and mouse up events from slider

6 Ansichten (letzte 30 Tage)
Etaoin Shrdlu
Etaoin Shrdlu am 8 Dez. 2016
Kommentiert: Jan am 11 Dez. 2016
I am implementing (in R2016a) a continuous slider using a listener as follows:
sld = uicontrol('Style', 'slider');
sld.addlistener('ContinuousValueChange', @(src, evt) callbk(src, evt));
What I also want to do is to have callbacks when the mouse is first clicked on the slider and then when it is released. I can't find any appropriate events to do this in the uicontrol class.
Does anyone have suggestions?

Akzeptierte Antwort

Jan
Jan am 9 Dez. 2016
Bearbeitet: Jan am 9 Dez. 2016
The standard callback of the slider is called, when the mouse is released:
function main
sld = uicontrol('Style', 'slider', 'Callback', {@callbk, 'released'});
sld.addlistener('ContinuousValueChange', @(h, e) callbk(h, e, 'moved'));
end
function callbk(SliderH, EventData, Event)
disp(Event)
end
The WindowButtonDownFcn does not trigger, when the mouse is over the slider.
Then Java helps:
function main
hSlider = uicontrol('style','slider');
jScrollBar = findjobj(hSlider);
jScrollBar.AdjustmentValueChangedCallback = @(h,e) callbk(h, e, 'moved');
jScrollBar.MousePressedCallback = @(h,e) callbk(h, e, 'clicked');
jScrollBar.MouseReleasedCallback = @(h,e) callbk(h, e, 'released');
end
function callbk(SliderH, EventData, Event)
disp(Event)
end
  2 Kommentare
Etaoin Shrdlu
Etaoin Shrdlu am 10 Dez. 2016
Thanks, Jan. This "undocumented Matlab" use of Java does the trick. Interestingly, it doesn't signal mouse up or down when the buttons on either end of the slider are pushed.
Jan
Jan am 11 Dez. 2016
@Etaoin: See the MouseClickedCallback. Further events: http://undocumentedmatlab.com/blog/uicontrol-callbacks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 8 Dez. 2016
I do not know if there are any listeners that can be configured for this. If there are not, then the figure property WindowButtonUpFcn is the only mouse-release callback.
  4 Kommentare
Jan
Jan am 9 Dez. 2016
You do not need the WindowButtonUpFcn, because the slider's Callback performs this action already.
Walter Roberson
Walter Roberson am 9 Dez. 2016
However if you have set the slider to disable then the slider's callback would not be active.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by