How to convert code to use EventControllerKey?

Recently I tried to use EventControllerKey instead connect keys signal, but sadly I found that functions which I choose, don’t ever execute.
This code in GTK 3 worked fine


but after change only this lines (also in GTK 3), clicking multiple times at tree_view content, don’t print anything to console(simple prints are inside opening_enter_function_ported function):

let evk = EventControllerKey::new(&tree_view);

You do need to add the EventControllerKey object to the widget you want to handle events from. In C that function is gtk_widget_add_controller().

In GTK3, you will need to keep the EventController instance around, otherwise it will be collected at the end of the scope and won’t exist any more.

In GTK4, you add the EventController to the widget, using gtk4::WidgetExt::add_controller.


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