GTK Drawing area keys not detected despite mask and focus are set

Hi, this is my code:

img_struct->image_area = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(vbox), img_struct->image_area);
gtk_widget_set_size_request(img_struct->image_area, 800, 450);

gtk_widget_set_hexpand(img_struct->image_area, TRUE);
gtk_widget_set_vexpand(img_struct->image_area, TRUE);
gtk_widget_set_halign(img_struct->image_area, GTK_ALIGN_CENTER);
gtk_widget_set_valign(img_struct->image_area, GTK_ALIGN_CENTER);
gtk_widget_set_events(img_struct->image_area, 
									  GDK_KEY_PRESS_MASK
									| GDK_BUTTON_PRESS_MASK
									| GDK_BUTTON_RELEASE_MASK
									| GDK_POINTER_MOTION_MASK);

gtk_widget_set_can_focus(img_struct->image_area, TRUE);
gtk_widget_grab_focus(img_struct->image_area);
g_signal_connect(img_struct->image_area , "draw",	  						G_CALLBACK( img_on_draw_event ), img_struct );
g_signal_connect(img_struct->image_area , "button-press-event",	G_CALLBACK( img_image_area_button_press ), img_struct );
g_signal_connect(img_struct->image_area , "button-release-event",G_CALLBACK( img_image_area_button_release ), img_struct );
g_signal_connect(img_struct->image_area , "motion-notify-event",  G_CALLBACK( img_image_area_motion ), img_struct);
g_signal_connect(img_struct->image_area , "key-press-event", 		G_CALLBACK(img_image_area_key_press), img_struct);

This code is part of a bigger application with accel group and another key-press-event set on the main window which contains the drawing area. Removing such event and the accel didn’t solve the problem.

Can anyone point me how to debug this annoying issue? It’s driving me nuts.

Have you tried using gtk_widget_set_has_window() before realizing the drawing area widget?

Yep I added it but no way. That snipped of code works beautifully on its own even without that call. Is there another way I can debug this? The inspector didn’t help sadly.

I solved in the meantime by using the main key event connected to the main window but I’m really curious to understand why it’s not working.

Ok I got it. The focus allowed on other widgets caused the problem.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.