Re: How to change the label on a menu.



Hi,

  I didn't see this copied to the list and I wanted the answer to be
archived and available for others future reference.

Thanks go to John Cupitt!

> Hi Dav, as long as you have a pointer to the menu item, it's
> easy. Just get the child of the GtkMenuItem with
> gtk_bin_get_child(), cast it to a label, and call
> gtk_label_set_text().
> 
>   GtkMenuItem *item = ....;
> 
>   GtkLabel *label = GTK_LABEL( gtk_bin_get_child( GTK_BIN( item ) ) );
> 
>   gtk_label_set_test( label, "foo!" );
> 
> Use gtk_item_factory_get_widget() to find a pointer to your menu item.
> 
> John
> 
> J. Davison de St. Germain wrote:
> >   Can someone tell me how to change the label on a menu item in GTK?
> > I've created the menu with a label (say: "Turn on Light") and when a
> > user selects it, I wish to change the lable (to say: "Turn off
> > Light").  I've looked at the API and can not find an applicable
> > function.  I've also looked at the source code and it appears that the
> > pointer to the label is "lost" and thus it might not be possible to 
> > do this.  Any help is greatly appreciated.

- Dav

-----------------------------------------------------------------------
- J. Davison de St. Germain         dav cs utah edu    (801) 581-4078 -
- Chief Software Engineer           http://www.cs.utah.edu/~dav       -
- SCI Institute, SE C-SAFE          University of Utah                -
-----------------------------------------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]