Gtk.Overlay
Gtk.Overlay — A container which overlays widgets on top of each other
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.Overlay
Functions:
- new
() -> Gtk.Widget
- add_overlay
(self, widget:Gtk.Widget)
- reorder_overlay
(self, child:Gtk.Widget, position:int)
- get_overlay_pass_through
(self, widget:Gtk.Widget) -> bool
- set_overlay_pass_through
(self, widget:Gtk.Widget, pass_through:bool)
Signals:
- “get-child-position”
(overlay, widget, allocation, user_data)
Description:
Gtk.Overlay
is a container which contains a single main child, on top of which it can place “overlay” widgets.
The position of each overlay widget is determined by its “halign” and “valign” properties. E.g. a widget with both alignments set to GTK_ALIGN_START will be placed at the top left corner of the Gtk.Overlay
container, whereas an overlay with halign set to GTK_ALIGN_CENTER and valign set to GTK_ALIGN_END will be placed a the bottom edge of the Gtk.Overlay
, horizontally centered. The position can be adjusted by setting the margin properties of the child to non-zero values.
More complicated placement of overlays is possible by connecting to the “get-child-position” signal.
GtkOverlay as Gtk.Buildable:
The Gtk.Overlay
implementation of the Gtk.Buildable interface supports placing a child as an overlay by specifying overlay
as the type
attribute of a \<child\>
element.
Function Details:
new()
new () -> Gtk.Widget
Creates a new Gtk.Overlay
.
Returns: a new
Gtk.Overlay
object.Since: 3.2
add_overlay()
add_overlay (self, widget:Gtk.Widget)
Adds widget
to overlay
.
The widget will be stacked on top of the main widgetadded with `Gtk.Container:add
().
The position at which
widget` is placed is determinedfrom its “halign” and “valign” properties.
- Since: 3.2
reorder_overlay()
reorder_overlay (self, child:Gtk.Widget, position:int)
Moves child
to a new index
in the list of overlay
children.The list contains overlays in the order that these wereadded to overlay
.
A widget’s index in the overlay
children list determines which orderthe children are drawn if they overlap. The first child is drawn atthe bottom. It also affects the default focus chain order.
get_overlay_pass_through()
get_overlay_pass_through (self, widget:Gtk.Widget) -> bool
Convenience function to get the value of the “pass-through”child property for widget
.
Returns: whether the widget is a pass through child.
Since: 3.18
set_overlay_pass_through()
set_overlay_pass_through (self, widget:Gtk.Widget, pass_through:bool)
Convenience function to set the value of the “pass-through”child property for widget
.
- Since: 3.18
Example:
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
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()