Best way to handle custom keyboard shortcuts in GTK4?

Hi all,
What’s the recommended way to implement custom keyboard shortcuts in a GTK4 app? I’ve seen different approaches and wondering what’s current best practice.

Thanks! :slight_smile:

If you’re using an action, you can use set_accels_for_action.

If you want to set shortcuts for a specific widget you can use Gtk.ShortcutController, which you add a Gtk.Shortcut to with a Gtk.ShortcutTrigger.

Specifically, Gtk.ShortcutController can be used in a UI file, which I think is very elegant.

3 Likes

Thanks mate … you are truely a talented monster! :slight_smile:

1 Like