Re: Understanding accelerators.





On 09/10/2014 20:53, Lucas Levrel wrote:
Le 7 octobre 2014, Oscar Lazzarino a écrit :

Let's say I have a window with just one button "quit". I'd like to
handle the <controlo>q key event to quit the application.

Here's how I set Return as accel in my GTK 2 app:

   gtkwin=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   accels=gtk_accel_group_new();
   gtk_window_add_accel_group(GTK_WINDOW(gtkwin),accels);
   ...
   button=gtk_button_new();
   gtk_box_pack_end( GTK_BOX(...), button, FALSE, FALSE, 0);
   button_img=gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON);
   gtk_button_set_image(GTK_BUTTON(button), button_img);
   g_signal_connect(button, "clicked", G_CALLBACK(...), ...);
   gtk_widget_add_accelerator(button, "clicked", accels,
                              gdk_keyval_from_name("Return"),
                              (GdkModifierType)0, GTK_ACCEL_LOCKED);

HTH.


That helped. Thanks

O.

--
Oscar Lazzarino (Software Architect and Senior Developer)
oscar lazzarino i-m3d com
im3D SpA - Medical Imaging Lab
http://www.i-m3d.com/
via Lessolo, 3 10153 Torino (TO) - Italy
tel:+39 011 19508773
fax:+39 011 19508968


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