I've got a GUI with some static text labels that I created in an .m file using the uicontrol() function. I made sure upon creation to set 'HitTest' to 'off'. I can check the controls after the fact, and indeed they all have 'HitTest' set to 'off'. However, I have a ButtonDownFcn call for the entire figure (I'm trying to tell when the user clicks on a specific piece of static text, but the text controls are generated dynamicall). If the user clicks on the figure background, the function executes properly. However, when the static text controls (with 'HitTest' set to 'off') are clicked on, the function fails to execute. Any ideas? Thanks!
"Ian Clarkson" <ian.clarkson@gesturetek.com> wrote in message news:fk6th4$9dd$1@fred.mathworks.com... > I've got a GUI with some static text labels that I created > in an .m file using the uicontrol() function. I made sure > upon creation to set 'HitTest' to 'off'. I can check the > controls after the fact, and indeed they all have 'HitTest' > set to 'off'. > > However, I have a ButtonDownFcn call for the entire figure > (I'm trying to tell when the user clicks on a specific > piece of static text, but the text controls are generated > dynamicall). > > If the user clicks on the figure background, the function > executes properly. However, when the static text controls > (with 'HitTest' set to 'off') are clicked on, the function > fails to execute. > > Any ideas? Yes. This is intended, documented behavior. http://www.mathworks.com/access/helpdesk/help/techdoc/ref/figure_props.html#ButtonDownFcn "A callback function that executes whenever you press a mouse button while the pointer is in the figure window, but not over a child object (i.e., uicontrol, uipanel, axes, or axes child)." If you set the static text control's ButtonDownFcn to the same function as your figure's ButtonDownFcn and set its Enable property to 'inactive', it should work the same way. http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/uicontrol_props.html#Enable -- Steve Lord slord@mathworks.com
"Steven Lord" <slord@mathworks.com> wrote in message <fk7l20$d5k$1@fred.mathworks.com>... > > "Ian Clarkson" <ian.clarkson@gesturetek.com> wrote in message > news:fk6th4$9dd$1@fred.mathworks.com... > > I've got a GUI with some static text labels that I created > > in an .m file using the uicontrol() function. I made sure > > upon creation to set 'HitTest' to 'off'. I can check the > > controls after the fact, and indeed they all have 'HitTest' > > set to 'off'. > > > > However, I have a ButtonDownFcn call for the entire figure > > (I'm trying to tell when the user clicks on a specific > > piece of static text, but the text controls are generated > > dynamicall). > > > > If the user clicks on the figure background, the function > > executes properly. However, when the static text controls > > (with 'HitTest' set to 'off') are clicked on, the function > > fails to execute. > > > > Any ideas? > > Yes. This is intended, documented behavior. > > http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ figure_props.html#ButtonDownFcn > > "A callback function that executes whenever you press a mouse button while > the pointer is in the figure window, but not over a child object (i.e., > uicontrol, uipanel, axes, or axes child)." > > If you set the static text control's ButtonDownFcn to the same function as > your figure's ButtonDownFcn and set its Enable property to 'inactive', it > should work the same way. > > http://www.mathworks.com/access/helpdesk/help/techdoc/ index.html?/access/helpdesk/help/techdoc/ref/ uicontrol_props.html#Enable > > -- > Steve Lord > slord@mathworks.com > > Thanks. As you suggested, I changed the control's Enable property to 'inactive', and it worked as expected. I was confused for two reasons: 1. HitTest, which is an available property for uicontrol types, has apparently no effect on their behaviour. Not sure why it exists at all, but I'm guessing it has something to do with an inheritance scheme that's in place. 2. To get the control to work as I would expect, I had to set the control's Enable property to 'inactive'. In my mind, when I want the control enabled (i.e. clicking on it causes the callback to take place), I want enable set to 'on'. A bit backward, in my opinion, but as you said, it is documented behaviour. We have a lot of hefty MATLAB manuals around here, but perhaps we're missing the one that details the GUI behaviours, because I couldn't find uicontrols referenced in any of them. Regardless, I'll try to spend more time poking around the online documentation. The only problem with that is that we have an older version of MATLAB that doesn't support some of the functions mentioned online. (I just realized that in newer versions, you can enable rotate3d for a set of axes, instead of an entire figure, which is what I'm currently forced to do). Thanks again for your help Steve, Ian.
"Ian Clarkson" <ian.clarkson@gesturetek.com> wrote in message news:fk8rm2$9ha$1@fred.mathworks.com... > "Steven Lord" <slord@mathworks.com> wrote in message > <fk7l20$d5k$1@fred.mathworks.com>... >> >> "Ian Clarkson" <ian.clarkson@gesturetek.com> wrote in > message >> news:fk6th4$9dd$1@fred.mathworks.com... >> > I've got a GUI with some static text labels that I > created >> > in an .m file using the uicontrol() function. I made > sure >> > upon creation to set 'HitTest' to 'off'. I can check the >> > controls after the fact, and indeed they all have > 'HitTest' >> > set to 'off'. >> > >> > However, I have a ButtonDownFcn call for the entire > figure >> > (I'm trying to tell when the user clicks on a specific >> > piece of static text, but the text controls are > generated >> > dynamicall). >> > >> > If the user clicks on the figure background, the > function >> > executes properly. However, when the static text > controls >> > (with 'HitTest' set to 'off') are clicked on, the > function >> > fails to execute. >> > >> > Any ideas? >> >> Yes. This is intended, documented behavior. >> >> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ > figure_props.html#ButtonDownFcn >> >> "A callback function that executes whenever you press a > mouse button while >> the pointer is in the figure window, but not over a child > object (i.e., >> uicontrol, uipanel, axes, or axes child)." >> >> If you set the static text control's ButtonDownFcn to the > same function as >> your figure's ButtonDownFcn and set its Enable property > to 'inactive', it >> should work the same way. >> >> http://www.mathworks.com/access/helpdesk/help/techdoc/ > index.html?/access/helpdesk/help/techdoc/ref/ > uicontrol_props.html#Enable >> >> -- >> Steve Lord >> slord@mathworks.com >> >> > > Thanks. > > As you suggested, I changed the control's Enable property > to 'inactive', and it worked as expected. I was confused > for two reasons: > > 1. HitTest, which is an available property for uicontrol > types, has apparently no effect on their behaviour. Not > sure why it exists at all, but I'm guessing it has > something to do with an inheritance scheme that's in place. You are correct that it has no effect on their behavior: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html#HitTest All Handle Graphics objects have certain properties (HitTest being one of them) -- some of those objects ignore some of the properties. http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f7-47570.html#f7-18090 > 2. To get the control to work as I would expect, I had to > set the control's Enable property to 'inactive'. In my > mind, when I want the control enabled (i.e. clicking on it > causes the callback to take place), I want enable set to > 'on'. A bit backward, in my opinion, but as you said, it is > documented behaviour. > > We have a lot of hefty MATLAB manuals around here, but > perhaps we're missing the one that details the GUI > behaviours, because I couldn't find uicontrols referenced > in any of them. One of the "manuals" I find useful for determining what Handle Graphics properties should do is the Handle Graphics Property Browser. If you type "doc matlab" at the >> prompt, it should be one of the items in the expanded tree for the MATLAB product in the left-hand frame. There should also be a link to it in the right-hand frame, although it may be under a different name. > Regardless, I'll try to spend more time > poking around the online documentation. The only problem > with that is that we have an older version of MATLAB that > doesn't support some of the functions mentioned online. (I > just realized that in newer versions, you can enable > rotate3d for a set of axes, instead of an entire figure, > which is what I'm currently forced to do). In that case, I'd recommend reading through the documentation that should have been installed at the same time as the product. That's the documentation for the version of the product(s) you have installed. You can access it using the Help Browser by entering "doc" at the >> prompt, by using the Start button, or by using the Help menu. > Thanks again for your help Steve, You're welcome. -- Steve Lord slord@mathworks.com