Why buttondownfcn of pushbutton not work in a classdef file ??!!!

조회 수: 2 (최근 30일)
Song
Song 2015년 4월 15일
댓글: Adam 2015년 4월 15일
I just want to build a pushbutton in a class defintion with a buttondown callback. But there is no reaction if I click the button.
If I change the 'buttondownfcn' to 'callback'. Then it will work. But I indeed need 'buttondownfcn' for my function.
Is this a Matlab bug or I missed something? I am using matlab 2011b.
Thanks guys.
classdef testBtnCbk
%TESTBTNCBK Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
function obj = testBtnCbk()
hfig = figure;
oTab.hBtn = uicontrol('style', 'pushbutton',...
'parent', hfig, ...
'backgroundcolor', [0 0 0], ...
'foregroundcolor', [1 1 1], ...
'string', 'hello', ...
'Units', 'pixel', ...
'buttondownfcn', @obj.pshbtnDwnCbk, ...
'Position', [100 100 100 100]);
end
function pshbtnDwnCbk(obj, ~, ~)
msgbox('hello')
end
end
end

채택된 답변

Song
Song 2015년 4월 15일
Ok, I find out why ... I have to set the property
'enable' -> 'inactive'
to invoke the callback.
  댓글 수: 1
Adam
Adam 2015년 4월 15일
Ah, I'd never really noticed that aspect of functionality. That will effectively disable its use as a pushbutton though so you would have to change enable back to 'on' at times you want it to actually behave as a pushbutton rather than having its buttondownfcn active.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2015년 4월 15일
편집: Adam 2015년 4월 15일
Yes, I just did a test and ButtonDownFcn does appear not to work. This is independent of being in a class. It is the same on command line.
However, I can think of no possible reason why you would need to use ButtonDownFcn on a pushbutton given that 'Callback' does exactly that.
  댓글 수: 1
Song
Song 2015년 4월 15일
I want to realize a function in GUI after pushing pushbutton then move the button if i hold the mouse left button and move. In this case, I need to address buttondown / buttonup function instead of click callback.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by