Re: Labels In Radio Buttons
- From: "Ian Frawley" <ifrawley opaltelecom co uk>
- To: "David Odin" <dindinx wanadoo fr>, "darren adams" <scottish-lad freeuk com>
- Cc: <gtk-app-devel-list gnome org>
- Subject: Re: Labels In Radio Buttons
- Date: Fri, 19 Oct 2001 13:27:34 +0100
Hi David,
Thanks for a very detailed response I am sure it will help.
Ian
----- Original Message -----
From: "David Odin" <dindinx wanadoo fr>
To: "darren adams" <scottish-lad freeuk com>
Cc: "Ian Frawley" <ifrawley opaltelecom co uk>;
<gtk-app-devel-list gnome org>
Sent: Friday, October 19, 2001 1:17 PM
Subject: Re: Labels In Radio Buttons
On Fri, Oct 19, 2001 at 12:27:44PM +0100, darren adams wrote:
Hello,
I've been inspired by the GTK+ tutorial (specifically,
http://www.gtk.org/tutorial/ch-widgetoverview.html#SEC-CASTING), and I
think
I have an answer.
I think that because a GtkRadioButton is a descendant of GtkButton, you
can
use casting to retrieve the label. This is better served in an example, so
have a look at the last line of this code example
Rather than:
GtkWidget *radio_button;
gchar *radio_button_label_text;
...
radio_button = gtk_radio_button_new_with_label(NULL, "This is my text");
/* This doesn't work: no label member in GtkRadioButton */
radio_button_label_text = GTK_TOGGLE_BUTTON(radio_button)->label;
/* This might work: there's a label member in GtkButton */
radio_button_label_text = GTK_BUTTON(radio_button)->label;
Please do not answer false statements on the list. It is really
misleading for people who need help.
GtkButton doesn't have a 'label' field. (Well, there's a label_text
field for the GtkButton of the upcomming GTK+-2.0, but I guess you're
using GTK+-1.2, and anyway, that's another story).
The fact is a GtkRadioButton, as all the descendant of GtkButton can
contain nearly any type of widget, and not only a label, so it would be
pointless for the GtkButton type to have a 'label' field.
Instead, GtkButton (and such, GtkRadioButton for our problem here) is
a descendant of a GtkBin container. The 'child' field of the GtkBin is a
pointer to the widget it contains.
When you use this code:
radio_button = gtk_radio_button_new_with_label(NULL, "text");
GTK really creates *two* widgets: a radio button (GtkRadioButton) and
a GtkLabel. Then the GtkLabel is put inside the radio button.
From here, you can access the GtkLabel of the GtkRadioButton with
this:
GTK_BIN(radio_button)->child
Note that, in this particular case, child is a GtkLabel, and then you
can retrieve the text of this label by using gtk_label_get().
To sum up,
given you have created the radio button like this:
radio_button = gtk_radio_button_new_with_label(NULL, "text");
you can retrieve the text of the button with this kind of code:
GtkWidget *label;
gchar *text;
label = GTK_BIN(radio_button)->child;
gtk_label_get(GTK_LABEL(label), &text);
IHTH.
DindinX
--
David Odin bigfoot com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]