Re: [gtk-list] Re: Accelerators again



On Thu, 12 Aug 1999, Joachim Klaehn wrote:

> Nils Rennebarth wrote:
> 
> > Noone answered my question about accelerators yet, so here it is again:
> >
> > How do make pressing a certain key (on the keyboard) in my application
> > to do the same as klicking a button?
> >
> > I.e.: there is a button:
> >
> >         button=gtk_button_new_with_label("Quit");
> >         gtk_signal_connect(GTK_OBJECT(button), "clicked",
> >                            GTK_SIGNAL_FUNC(delete), NULL);
> >
> > and I would like to make pressing "q" to do the same, that is to call the
> > delete function.
> >
> > How do I do this?
> >
> > Nils
> >
> 
> Hello Nils,
> 
> I´m doing the job in this way:
> 
>   GtkWidget *window;
>   GtkAccelGroup *AccelGroup;
> 
>   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> 
>   AccelGroup = gtk_accel_group_new ();
>   gtk_accel_group_attach (AccelGroup, GTK_OBJECT (window));

gtk_accel_group_attach() is an internal function,
use gtk_window_add_accel_group() instead.

>   button=gtk_button_new_with_label("Quit");
>   gtk_signal_connect(GTK_OBJECT(button), "clicked",
>                      GTK_SIGNAL_FUNC(delete), NULL);
> 
>   gtk_widget_add_accelerator(button,"clicked",&AccelGroup,
>         GDK_q,0,
>         GTK_ACCEL_VISIBLE|GTK_ACCEL_SIGNAL_VISIBLE);

keep in mind that the GTK_ACCEL_*VISIBLE flags are only evaluated
if you are using a GtkAccelLabel, e.g. instead of creating a
button with an ordinary label:
   button = gtk_button_new_with_label ("Quit");
you'd create it with an accelerator label:
   button = gtk_button_new ();
   label = gtk_accel_label_new ("Quit");
   gtk_widget_show (label);
   gtk_conatiner_add (GTK_CONTAINER (button), label);
   gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), button);

then GTK_ACCEL_VISIBLE and GTK_ACCEL_SIGNAL_VISIBLE will actually
take effect (the accelerator bindings for the button are displayed).

> 
> good luck
> 
> Achim
> 

---
ciaoTJ



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