Re: Understanding accelerators.



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.


--
Lucas Levrel


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