Re: [gtk-list] Underlining of labels with Glade



Anders Melchiorsen wrote:
> 
> I would figure that this is a FAQ, but I was unable to find a
> solution.
> 
> What I want is underlining of a letter in a label, to tell what
> keyboard accelerator is used for the widget that the label
> describes. How can I do this via Glade?
> 
> I have the same problem for menus, by the way.

Glade doesn't support it at present, mainly because I didn't understand how it
worked myself.

I think this is the correct way to use underlined labels and accelerators so
that an entry or other widget grabs the focus when the key is pressed
(someone please tell me if this isn't correct!):


  accel_group = gtk_accel_group_new ();
  gtk_accel_group_attach (accel_group, GTK_OBJECT (window1));

  accellabel1 = gtk_accel_label_new ("");
  accel_key = gtk_label_parse_uline (GTK_LABEL (accellabel1), "_My Entry");
  gtk_widget_show (accellabel1);
  gtk_table_attach (GTK_TABLE (table1), accellabel1, 0, 1, 1, 2,
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

  entry1 = gtk_entry_new ();
  gtk_widget_show (entry1);
  gtk_table_attach (GTK_TABLE (table1), entry1, 1, 2, 1, 2,
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

  gtk_widget_add_accelerator (entry1, "grab_focus", accel_group,
                              accel_key, GDK_MOD1_MASK, 0);


In Glade, I'll try to make this as simple as possible. i.e. all you have to
do is type the underline character in the GtkAccelLabel's label. You'll be
able to set which widget the accelerator is meant for, but it will also
default to the widget on the right of, or below, the label.


For menus, I can pinch the code in GtkItemFactory. You need to create 2
accelerators there - the global accelerator key shown on the menu, and
the underlined accelerator key, local to the menu.

Damon



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