1

I want to set a mnemonic underline in a button called Quit, but this underline is not displayed though keyboard acceleration works by pressing ALT and the specified mnemonic key. In the code I have set use-underline to true. but it just doesn't work. I want the Q character to be underlined so that the Q character is recognizable as menemonic to the user. What am I doing wrong?

Here is my simplified main code:

#include <gtk/gtk.h>
#include <glib/gstdio.h>

static void activate (GtkApplication *app, gpointer user_data) {
  GtkBuilder *builder = gtk_builder_new ();
  gtk_builder_add_from_file (builder, "builder1.ui", NULL);
  GObject *window = gtk_builder_get_object (builder, "window");
  gtk_window_set_application (GTK_WINDOW (window), app);
  gtk_widget_show (GTK_WIDGET (window));
}

int main (int argc, char *argv[]) {
#ifdef GTK_SRCDIR
  g_chdir (GTK_SRCDIR);
#endif

  GtkApplication *app = gtk_application_new ("org.gtk.example", 
G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);

  int status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

Here is my builder code:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object id="window" class="GtkWindow">

    <property name="title">Grid</property>
    <child>
      <object id="grid" class="GtkGrid">
        <child>
          <object id="quit" class="GtkButton">
            <property name="use-underline">true</property>
            <property name="label">_Quit</property>
            <property name="has-frame">true</property>
            <layout>
              <property name="column">1</property>
              <property name="row">2</property>
              <property name="column-span">1</property>
            </layout>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
Ramses
  • 652
  • 2
  • 8
  • 30

0 Answers0