Re: radio buttons



samuel.berthelot wrote:

Hi I'm using GTK 1.2 (have to)

YUK!

and I have a problem with using radio buttons.
I have 3 and I can switch between the 1st and the 3rd ones, but as soon as I click on the 2nd it remains clicked.
Here is a snippet of my code :

     rbutStyle = gtk_radio_button_new_with_label (NULL, "Points");
        gtk_widget_show (rbutStyle);
        gtk_box_pack_start (GTK_BOX (vbox8), rbutStyle, FALSE, FALSE, 0);
        
        rbutStyle_group = gtk_radio_button_group ( rbutStyle );

radiobutton5 = gtk_radio_button_new_with_label (rbutStyle_group, "WireFrame");
        gtk_widget_show (radiobutton5);
        gtk_box_pack_start (GTK_BOX (vbox8), radiobutton5, FALSE, FALSE, 0);
        
radiobutton6 = gtk_radio_button_new_with_label (rbutStyle_group, "Polygons");
        gtk_widget_show (radiobutton6);
        gtk_box_pack_start (GTK_BOX (vbox8), radiobutton6, FALSE, FALSE, 0);
        
        gtk_toggle_button_set_state ( rbutStyle, TRUE );
        gtk_toggle_button_set_state ( radiobutton5, FALSE );
        gtk_toggle_button_set_state ( radiobutton6, FALSE );


After adding radiobutton5, rbutStyle_group (a GSLIST*) becomes invalid because it gets reallocated. You have to retrieve the rbutStyle_group pointer again by calling this line of code before adding radiobutton6:

rbutStyle_group = gtk_radio_button_group ( GTK_RADIO_BUTTON(radiobutton5) );

BTW, I think your code would look much cleaner like this:

rbutStyle = gtk_radio_button_new_with_label (NULL, "Points");
gtk_box_pack_start (GTK_BOX (vbox8), rbutStyle, FALSE, FALSE, 0);

rbutStyle_group = gtk_radio_button_group ( rbutStyle );
radiobutton5 = gtk_radio_button_new_with_label (rbutStyle_group, "WireFrame");
gtk_box_pack_start (GTK_BOX (vbox8), radiobutton5, FALSE, FALSE, 0);

rbutStyle_group = gtk_radio_button_group (GTK_RADIO_BUTTON(radiobutton5));
radiobutton6 = gtk_radio_button_new_with_label (rbutStyle_group, "Polygons");
gtk_box_pack_start (GTK_BOX (vbox8), radiobutton6, FALSE, FALSE, 0);
        
gtk_toggle_button_set_state ( rbutStyle, TRUE );
gtk_widget_show_all (vbox8);

You don't need to call gtk_toggle_button_set_state() for every radio button in a group. Setting the active 
state for one radio button in a group automatically unsets the active state for all the other buttons in that 
group (it does in GTK2 so I presume it's the same in GTK 1.2). If you add all the radio buttons to their own 
vbox you can then make one call gtk_widget_show_all(). Also I don't think it's a good idea to show a widget 
before packing it into a box.

Regards,

Jeff.






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