Overlay

An Overlay widget provides a container which a child widget can be packed into. The widget is displayed over a larger, background widget to provide a floating object.

Constructor

The Overlay can be constructed using the following:

overlay = Gtk.Overlay()

Methods

The background or larger item can be added to the overlay with the method:

overlay.add(widget)

Overlay widgets can be then added using:

overlay.add_overlay(widget)

Input made on the Overlay widget can be passed through to the unlying widget with:

overlay.set_overlay_pass_through(widget, pass_through)

The widget parameter should be set to the underlying widget which will receive input. The pass_through parameter should be set to True or False as to whether this functionality is enabled or not.

Example

Below is an example of a Overlay:

#!/usr/bin/env python

from gi.repository import Gtk

window = Gtk.Window()
window.set_default_size(200, 200)
window.connect("destroy", Gtk.main_quit)

overlay = Gtk.Overlay()
window.add(overlay)

textview = Gtk.TextView()
textview.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
textbuffer = textview.get_buffer()
textbuffer.set_text("Welcome to the PyGObject Tutorial\n\nThis guide aims to provide an introduction to using Python and GTK+.\n\nIt includes many sample code files and exercises for building your knowledge of the language.", -1)
overlay.add(textview)

button = Gtk.Button(label="Overlayed Button")
button.set_valign(Gtk.Align.CENTER)
button.set_halign(Gtk.Align.CENTER)
overlay.add_overlay(button)

overlay.show_all()

window.show_all()

Gtk.main()

Download: Overlay