0
votes

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

1
Show some code pleasedrahnr

1 Answers

1
votes

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.