Hi, I start develop with C and Gtk4. Now I have a little problem. Gtk Event Controller Key works fine with TextView and Button but not with GtkEntry. Can’t find anything in the web. Have you a idea? Thank you.
static gboolean test( GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
gpointer user_data)
{
g_print("%i --- %i\n", keyval, keycode );
return FALSE;
}
static void app_activate (GApplication *app, gpointer user_data)
{
GtkWidget *win, *tv;
GtkEventController *contr = gtk_event_controller_key_new();
win = gtk_application_window_new( GTK_APPLICATION( app ) );
gtk_window_set_title( GTK_WINDOW( win ), "Test");
gtk_window_set_default_size( GTK_WINDOW( win ), 200, 150 );
//tv = gtk_button_new_with_label("test"); // OK
//tv = gtk_text_view_new (); // OK
tv = gtk_entry_new(); // NOT OK ?!
gtk_widget_set_focusable( GTK_WIDGET( tv ), TRUE );
gtk_widget_add_controller( tv , contr );
gtk_window_set_child( GTK_WINDOW( win ), tv );
g_signal_connect( contr, "key-pressed", G_CALLBACK( test ), tv );
gtk_widget_show( win );
}