Re: Radiobuttons dont work?



 
I'm not writing to answer your question, unfortunately (as I haven't yet set up GTK at home, only at work), but I thought I would comment on the code itself (and this may or may not be helpful):
 
Please consider taking the 'if i==1' thing out of the loop... Do your initialization before you enter the loop, then make the loop 'for i = 2 to 5' instead of 1 to 5.  The way your code is written it's not only doing an unnecessary compare, it's not only less readable, but it's also doing that unnecessary compare with a branch *four* times in the loop.  X-windows is slow enough without bad code making it worse. 
 
-Rob
 
----- Original Message -----
From: AndreKüster
Sent: Sunday, May 20, 2001 2:11 PM
To: gtk-list gnome org
Subject: Radiobuttons dont work?
 
Hi,

I`ve a problem with Radiobuttons:
When I write the following code, the radiobutton array doesnt work, the
middle buttons act like normal
togglebuttons if the first radiobutton is active, very strange:

#include <gtk/gtk.h>

void main(int argc, int *argv[]) {
   GSList * group;
   GtkWidget *window,*rb,*box;
   int i ;

   gtk_init(&argc, &argv);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   box = gtk_hbox_new(TRUE, 0);

   for (i=1;i<=5;i++) {
       if (i==1) {
           rb = gtk_radio_button_new_with_label(NULL,"test123");
           group = gtk_radio_button_group(GTK_RADIO_BUTTON(rb));
       }
       else rb = gtk_radio_button_new_with_label(group,"test123");
       gtk_box_pack_start_defaults(GTK_BOX(box),GTK_WIDGET(rb));
   }

   gtk_widget_show_all(box);
   gtk_container_add(GTK_CONTAINER(window),box);
   gtk_widget_show_all(window);
   gtk_main();
   return 0;
}

Where is my mistake? First I found this in gtk-1.3.5 but I could also
reproduce it in the current stable version...


Thanks in advance,
                           Andre.



_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list


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