GtkDropDown

gtk.drop_down.DropDown is a widget that allows the user to choose an item from a list of options.

An example GtkDropDown

The gtk.drop_down.DropDown displays the selectedgtk.drop_down.DropDown.guint choice.

The options are given to gtk.drop_down.DropDown in the form of gio.list_model.ListModel and how the individual options are represented is determined by a gtk.list_item_factory.ListItemFactory. The default factory displays simple strings, and adds a checkmark to the selected item in the popup.

To set your own factory, use gtk.drop_down.DropDown.setFactory. It is possible to use a separate factory for the items in the popup, with gtk.drop_down.DropDown.setListFactory.

gtk.drop_down.DropDown knows how to obtain strings from the items in a gtk.string_list.StringList; for other models, you have to provide an expression to find the strings via gtk.drop_down.DropDown.setExpression.

gtk.drop_down.DropDown can optionally allow search in the popup, which is useful if the list of options is long. To enable the search entry, use gtk.drop_down.DropDown.setEnableSearch.

Here is a UI definition example for gtk.drop_down.DropDown with a simple model:

<object class="GtkDropDown">
  <property name="model">
    <object class="GtkStringList">
      <items>
        <item translatable="yes">Factory</item>
        <item translatable="yes">Home</item>
        <item translatable="yes">Subway</item>
      </items>
    </object>
  </property>
</object>

If a gtk.drop_down.DropDown is created in this manner, or with gtk.drop_down.DropDown.newFromStrings, for instance, the object returned from gtk.drop_down.DropDown.getSelectedItem will be a gtk.string_object.StringObject.

To learn more about the list widget framework, see the overview.

CSS nodes

gtk.drop_down.DropDown has a single CSS node with name dropdown, with the button and popover nodes as children.

Accessibility

gtk.drop_down.DropDown uses the gtk.types.AccessibleRole.ComboBox role.

struct GtkDropDown