Debian Codegraph @

docs/tutorials/gtk4/popovers.rst

raw
1 .. currentmodule:: gi.repository
2
3 Popovers
4 ========
5
6 The :class:`Gtk.Popover` is an special kind of window used for displaying
7 additional information and is often used with button menus and context menus.
8 Popovers are attached to a parent widget and point to it.
9 It's position can be configured with :attr:`Gtk.Popover.props.position`.
10 :class:`Gtk.Popover` shows an arrow to visually connect where it points to,
11 this can be disabled setting :attr:`Gtk.Popover.props.has_arrow` to ``False``.
12
13 A :class:`Gtk.Popover` can be opened using :meth:`Gtk.Popover.popup` and hidden
14 with :meth:`Gtk.Widget.hide`.
15
16 GTK also provides :class:`Gtk.MenuButton`, it's an special button that can show
17 and hide a :class:`Gtk.Popover` attached to it using
18 :attr:`Gtk.MenuButton.props.popover`.
19
20 Custom Popover
21 --------------
22
23 A child widget can be added to a popover using :meth:`Gtk.Popover.set_child`.
24 The parent of the popover can be set using :meth:`Gtk.Widget.set_parent`.
25
26 Example
27 ^^^^^^^
28
29 .. image:: images/popover.png
30
31 .. literalinclude:: examples/popover.py
32 :linenos:
33
34
35 Menu Popover
36 ------------
37
38 GTK also has :class:`Gtk.PopoverMenu`, it's a :class:`Gtk.Popover` subclass
39 designed to display a menu model.
40
41 A popover can be created from a :class:`Gio.MenuModel` using
42 :meth:`Gtk.PopoverMenu.new_from_model` and can be changed after creation with
43 :attr:`Gtk.PopoverMenu.props.menu_model`.
44
45 :class:`Gtk.MenuButton` also can construct a :class:`Gtk.PopoverMenu` passing it
46 a :class:`Gio.MenuModel` to :attr:`Gtk.MenuButton.props.menu_model`.
47
48 .. seealso::
49 In :doc:`GTK Application </tutorials/gtk4/application>` we also showed examples of menu
50 models.
51
52 Example
53 ^^^^^^^
54
55 .. image:: images/popover_menu.png
56
57 .. literalinclude:: examples/popover_menu.py