GtkLabel and connect_clicked

So I’m trying to call a function when a GtkLabel is clicked, and I know connect_clicked exists for GtkButton, connect_closure for more specific events, etc.

But I can’t seem to find a solution for GtkLabel (except for Gestures, which seem to wrap the label in yet another widget), so is there a proper way of handling click events on labels?

I think you need to use GtkGestureClick, it is the same thing a button uses to handle the click.

2 Likes

Is there a specific reason you can’t use a button in your case?

no, Gestures (and others event controllers) are not widgets, they’re just convenient interfaces that do some filtering/preprocessing.

Just add a Gtk.GestureClick to your Label with add_controller() to start listening for click events.

Alternatively, use a Gtk.Button with has-frame=FALSE.

1 Like