How to trigger event on key-pressed?

,

Hi everybody ! I’ve made a custom widget that implement GtkEditable with a GtkText, and I’d like to trigger an action when the user is typing and press enter. And I can’t figure how to do that.
Any help is welcome, thanks !

I’ve managed to solve the issue, with a GtkEventControllerKey, and added it to the GtkText widget inside my custom widget and connecting the signal key-pressed to the callback I wanted. But I wonder why it didn’t work when I added the event controller to self.
And I wonder why It only triggers the callback only when the key pressed is not a character.

Because the widget that has the key focus is the delegate GtkText widget, not the widget outside.

You could use an event controller with a capture phase, so the parent widget of the GtkText would end up capturing the Return key first.

There is no such thing as “a character”: there are only events.

What I mean, is that the “key-pressed” event seems emitted only when I pressed a key that not represent a character.

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