Re: modifiable dialog button labels?

From: Roger Davis <rbd soest hawaii edu>
To: Lance Dillon <riffraff169 yahoo com> 
Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org> 
Sent: Thursday, March 8, 2012 2:07 AM
Subject: Re: modifiable dialog button labels?

On Wed, 7 Mar 2012, Lance Dillon wrote:

you can use gtk_get_action_area() to get the GtkBox that that is the action
area, that itself contains the buttons.  I believe you can then get all the
child widgets, which would be the GtkButtons.

The  docs for GtkDialog describes it some, but doesn't talk about getting the
buttons.  I think you would have to go to the page for GtkBox for how to get
the children.

Hi Lance,

The GtkDialog documentation tells only how to access the action area, not its children. Searching around I 
see a gtk_container_get_children() which presumably returns a list of GtkWidget pointers. Is there a way I 
can look at a widget pointer and detrmine the widget's type, i.e., figure out whether or not it's a button? 
I see references to a gtk_widget_get_type() on the web, but no good examples of how it's used, and it 
appears to be not present at all in my own GTK release's GtkWidget documentation. There also seem to be some 
related type discovery functions in the gobject library such as g_type(), etc., but so far I have not found 
any useful examples of how I might use them to figure out if any particular widget pointer is a button or 



You would then use g_type_is_a() (possibly), perhaps with G_TYPE_FROM_INSTANCE and g_type_from_name():

GList *g,*g1;


if (g_type_is_a(G_TYPE_FROM_INSTANCE(g1->data),g_type_from_name("GtkButton"))) {
  /* do something with button */


You can of course create the dialog without buttons with gtk_dialog_new(), then add buttons manually with 
gtk_dialog_add_button(), and save the return value which is the widget, then change the labels on the 
buttons  when you need to.  That may be easier than the above:

GtkWidget *d;
GtkButton *b1,*b2;

Then do your gtk_dialog_run() later.  Then when you need to change the values, you can just do 
gtk_button_set_label(b1,"Dog"); gtk_button_set_label(b2,"Cat"), then reshow your dialog and gtk_dialog_run() 

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