2

We can add a button click event in gtk-rs like this

let btn: Button = builder.get_object("button1").expect("Cant get button");
btn.connect_clicked(|_| {
        println!("Activated");
    });

like the above code how can I add similar click event for entry box such that when I press the mouse on the entry box it should print pressed. I tried this

let entry: Entry =  builder.get_object("box1").expect("Cant get box");
entry.connect_icon_press(|_, _, _| {
    println!("pressed");
});

The program is compiling without any error but when I clicked on the entry box I expected to see pressed in terminal but instead there is nothing.

Eka
  • 14,170
  • 38
  • 128
  • 212
  • 2
    [`connect_button_press_event`](https://gtk-rs.org/docs/gtk/trait.WidgetExt.html#tymethod.connect_button_press_event) and [`connect_button_release_event`](https://gtk-rs.org/docs/gtk/trait.WidgetExt.html#tymethod.connect_button_release_event) should work for any widget. – Jmb Apr 12 '21 at 08:45
  • 1
    `connect_icon_press` is for pressing the activatable icon that can be embedded inside an entry. – user4815162342 Apr 12 '21 at 11:04
  • Thank you, that worked, may I ask in gtk-rs why some times we have to return `Inhibit(true)` in some closures? – Eka Apr 12 '21 at 12:45
  • 1
    @Eka because signal emitter expects you to provide a return value. In `GSourceFunc` it shows whether function should be scheduled again, in events it allows you to stop or propagate event handling (look at `returns` section [here](https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-button-press-event)) – Alexander Dmitriev Apr 13 '21 at 06:35

0 Answers0