[Glade-users] Getting widget references in callback functions



http://glade.pn.org/FAQ

3.4 How do I get a pointer to a widget from within a signal handler?

Use the lookup_widget() function provided. (It can be found in
support.c)

You pass it a pointer to any widget in a window, and the name of the
widget that you want to get. Usually in signal handlers you can use the
first argument to the signal handler as the first parameter to
lookup_widget(), e.g.

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GtkWidget *entry1;

  entry1 = lookup_widget (GTK_WIDGET (button), "entry1");

  ...
}


Note that this does not work if you are using libglade. The
corresponding code for libglade would be:

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
  GladeXML* xml;
  GtkWidget* entry1;

  xml = glade_get_widget_tree (GTK_WIDGET (button1));
  entry1 = glade_xml_get_widget (xml, "entry1");

  ...
}


-- 
James Cameron                                      (cameron stl dec com)





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