GtkOverlay not passing through input events

1k views Asked by At

The GtkOverlay widget has a special set_overlay_pass_through method to pass inputs through to underlying overlays. I want to use this feature to overlay a GtkDrawingArea over the UI to add drawings. Unfortunately, it does not work for me, no input events are passed through.

Im using msys2 and gtkmm.

This is my code:

Gtk::DrawingArea drawingArea;
Gtk::Fixed nodeBox; //filled with several widgets
Gtk::Overlay overlay;
overlay.add_overlay(nodeBox);
overlay.add_overlay(drawingArea);
overlay.set_overlay_pass_through(drawingArea,true);
window.add(overlay);

When I change the order of the two add_overlay calls, the inputs events work normally, but the widget of nodeBox hide the drawing area.

1

There are 1 answers

0
pan-mroku On

DrawingArea captures events because it has Gdk::Window.

Compare with Misc:

This is an abstract for a set of utility widgets that lack a physical window. They do have alignment and padding within their defined space.

Without a window, widgets of this type cannot capture events.

For set_overlay_pass_through to work you need to use Label, Arrow, Image or manually set Gdk::Window to pass events:

overlay.set_overlay_pass_through(drawingArea,true);
drawingArea.signal_realize().connect([&]
{
    auto gdkWindow = drawingArea.get_window();
    gdkWindow->set_pass_through(true);
});

Note that you still need to call set_overlay_pass_through and widget must be realized.