-1

I am using GTK+2 for GUI in C language. I have 10x10 table of buttons in my code. And When I run my code, the 1st button (button[0][0]) is focused by default. So how can I can prevent this button to be focused by default?

Code:

table = gtk_table_new(10, 10, TRUE);

for (int row=0; row<10; row++) {
    for (int col=0; col<10; col++) {
        button[row][col] = gtk_button_new_with_label(" ");
        g_signal_connect(G_OBJECT(button[row][col]), "button-release-event", G_CALLBACK(buttonClicked), NULL);
        gtk_button_set_focus_on_click(GTK_BUTTON(button[row][col]), FALSE);
        gtk_table_attach_defaults(GTK_TABLE(table), button[row][col], col, col+1, row, row+1);
    }
}
Raees Khan
  • 371
  • 1
  • 5
  • 20

1 Answers1

0

When you show the window, call gtk_widget_grab_focus() on the widget that you want to focus instead.

If you don't want the buttons in the grid to be able to focus at all, then call gtk_widget_set_can_focus() on them.

ptomato
  • 56,175
  • 13
  • 112
  • 165