Akshit Khurana
Akshit Khurana

Reputation: 694

How to hide Gtk widget on clicking outside it?

I have a custom GTK widget (basically an overlay of HBox over a Cairo surface). I wish to hide it when I click outside the widget in the window. Similar to how menus behave.

I tried using grab_focus and wait for the focus-out-event but the widget doesn't grab focus, I think it's not a focusable widget.[1]

[1] https://developer.gnome.org/pygtk/2.24/class-gtkwidget.html#method-gtkwidget--grab-focus

Upvotes: 0

Views: 1623

Answers (1)

jcoppens
jcoppens

Reputation: 5440

You might have to set the CAN_FOCUS flag, if you want to use the focus_out event.

But if you want to click outside to hide the widget, as is necessary with menus, then you have to connect to events of the area below the widget. You could connect to the button_press event of the window, taking care not to stop event propagation.

Upvotes: 1

Related Questions