Debian Codegraph @

docs/tutorials/gtk4/controls/dropdown.rst

raw
1 .. currentmodule:: gi.repository
2
3 DropDown
4 ========
5 :class:`Gtk.DropDown` allows the user to choose an item from a list of options.
6 They are preferable to having many radio buttons on screen as they take up less
7 room.
8
9 To populate its options :class:`Gtk.DropDown` uses a :class:`Gio.ListModel`.
10 :class:`Gio.ListModel` it's an interface that represents a mutable list of
11 :class:`GObject.Objects <GObject.Object>`. For text-only uses cases GTK provides
12 :class:`Gtk.StringList`, a list model that wraps an array of strings wrapped on
13 :class:`Gtk.StringObject` and :class:`Gtk.DropDown` knows how to use it.
14
15 :class:`Gtk.DropDown` can optionally allow search in the popup, which is useful
16 if the list of options is long. To enable the search entry, use
17 :attr:`Gtk.DropDown.props.enable_search`.
18
19 .. attention::
20 If you use custom list models with custom gobjects you must provide a
21 :class:`Gtk.Expression` through :attr:`Gtk.DropDown.props.expression` so
22 :class:`Gtk.DropDown` can know how to filter the gobjects.
23 :class:`Gtk.Expression` has been supported in PyGObject since release 3.48.
24
25 :class:`Gtk.DropDown` stores the selected item from the list model in
26 :attr:`Gtk.DropDown.props.selected_item`, and the position of that item on
27 :attr:`Gtk.DropDown.props.selected`. To know when the selection has changed just
28 connect to ``notify::selected-item`` or ``notify::selected``.
29
30
31 Example
32 ^^^^^^^
33
34 We are creating a simple :class:`Gtk.DropDown` using :class:`Gtk.StringList`.
35
36 .. image:: images/dropdown.png
37
38 .. literalinclude:: examples/dropdown.py
39 :linenos: