Gtk.DropDown¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted to when the drop down is activated. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.DropDown(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
GtkDropDown
is a widget that allows the user to choose an item from a list of options.An example
Gtk.DropDown
The
GtkDropDown
displays the ‘selected [property@Gtk.DropDown:selected]’ choice.The options are given to
GtkDropDown
in the form ofGListModel
and how the individual options are represented is determined by a [class`Gtk`.ListItemFactory]. The default factory displays simple strings, and adds a checkmark to the selected item in the popup.To set your own factory, use [method`Gtk`.DropDown.set_factory]. It is possible to use a separate factory for the items in the popup, with [method`Gtk`.DropDown.set_list_factory].
GtkDropDown
knows how to obtain strings from the items in a [class`Gtk`.StringList]; for other models, you have to provide an expression to find the strings via [method`Gtk`.DropDown.set_expression].GtkDropDown
can optionally allow search in the popup, which is useful if the list of options is long. To enable the search entry, use [method`Gtk`.DropDown.set_enable_search].Here is a UI definition example for
GtkDropDown
with a simple model:```xml
<items> Factory</item> Home</item> Subway</item> </items> </object>
/object ```
To learn more about the list widget framework, see the [overview](section-list-widget.html).
## CSS nodes
`:obj:Gtk.DropDown` has a single CSS node with name dropdown, with the button and popover nodes as children.
## Accessibility
`:obj:Gtk.DropDown` uses the
Gtk.AccessibleRole.COMBO_BOX
role.- classmethod new(model, expression)[source]¶
- Parameters:
model (
Gio.ListModel
orNone
) – the model to useexpression (
Gtk.Expression
orNone
) – the expression to use
- Returns:
a new
GtkDropDown
- Return type:
Creates a new
GtkDropDown
.You may want to call [method`Gtk`.DropDown.set_factory] to set up a way to map its items to widgets.
- classmethod new_from_strings(strings)[source]¶
- Parameters:
strings ([
str
]) – The strings to put in the dropdown- Returns:
a new
GtkDropDown
- Return type:
Creates a new
GtkDropDown
that is populated with the strings.
- get_expression()[source]¶
- Returns:
a
GtkExpression
- Return type:
Gets the expression set that is used to obtain strings from items.
See [method`Gtk`.DropDown.set_expression].
- get_factory()[source]¶
- Returns:
The factory in use
- Return type:
Gets the factory that’s currently used to populate list items.
The factory returned by this function is always used for the item in the button. It is also used for items in the popup if [property`Gtk`.DropDown:list-factory] is not set.
- get_header_factory()[source]¶
- Returns:
The factory in use
- Return type:
Gets the factory that’s currently used to create header widgets for the popup.
New in version 4.12.
- get_list_factory()[source]¶
- Returns:
The factory in use
- Return type:
Gets the factory that’s currently used to populate list items in the popup.
- get_model()[source]¶
- Returns:
The model in use
- Return type:
Gets the model that provides the displayed items.
- get_search_match_mode()[source]¶
- Returns:
the match mode of the search filter
- Return type:
Returns the match mode that the search filter is using.
New in version 4.12.
- get_selected()[source]¶
- Returns:
the position of the selected item, or
Gtk.INVALID_LIST_POSITION
if not item is selected- Return type:
Gets the position of the selected item.
- get_selected_item()[source]¶
- Returns:
The selected item
- Return type:
Gets the selected item. If no item is selected,
None
is returned.
- set_enable_search(enable_search)[source]¶
- Parameters:
enable_search (
bool
) – whether to enable search
Sets whether a search entry will be shown in the popup that allows to search for items in the list.
Note that [property`Gtk`.DropDown:expression] must be set for search to work.
- set_expression(expression)[source]¶
- Parameters:
expression (
Gtk.Expression
orNone
) – aGtkExpression
Sets the expression that gets evaluated to obtain strings from items.
This is used for search in the popup. The expression must have a value type of
GObject.TYPE_STRING
.
- set_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactory
orNone
) – the factory to use
Sets the
GtkListItemFactory
to use for populating list items.
- set_header_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactory
orNone
) – the factory to use
Sets the
GtkListItemFactory
to use for creating header widgets for the popup.New in version 4.12.
- set_list_factory(factory)[source]¶
- Parameters:
factory (
Gtk.ListItemFactory
orNone
) – the factory to use
Sets the
GtkListItemFactory
to use for populating list items in the popup.
- set_model(model)[source]¶
- Parameters:
model (
Gio.ListModel
orNone
) – the model to use
Sets the
GListModel
to use.
- set_search_match_mode(search_match_mode)[source]¶
- Parameters:
search_match_mode (
Gtk.StringFilterMatchMode
) – the new match mode
Sets the match mode for the search filter.
New in version 4.12.
- set_selected(position)[source]¶
- Parameters:
position (
int
) – the position of the item to select, orGtk.INVALID_LIST_POSITION
Selects the item at the given position.
Signal Details¶
- Gtk.DropDown.signals.activate(drop_down)¶
- Signal Name:
activate
- Flags:
- Parameters:
drop_down (
Gtk.DropDown
) – The object which received the signal
Emitted to when the drop down is activated.
The
::activate
signal onGtkDropDown
is an action signal and emitting it causes the drop down to pop up its dropdown.New in version 4.6.
Property Details¶
- Gtk.DropDown.props.enable_search¶
- Name:
enable-search
- Type:
- Default Value:
- Flags:
Whether to show a search entry in the popup.
Note that search requires [property`Gtk`.DropDown:expression] to be set.
- Gtk.DropDown.props.expression¶
- Name:
expression
- Type:
- Default Value:
- Flags:
An expression to evaluate to obtain strings to match against the search term.
See [property`Gtk`.DropDown:enable-search] for how to enable search. If [property`Gtk`.DropDown:factory] is not set, the expression is also used to bind strings to labels produced by a default factory.
- Gtk.DropDown.props.factory¶
- Name:
factory
- Type:
- Default Value:
- Flags:
Factory for populating list items.
- Gtk.DropDown.props.header_factory¶
- Name:
header-factory
- Type:
- Default Value:
- Flags:
The factory for creating header widgets for the popup.
New in version 4.12.
- Gtk.DropDown.props.list_factory¶
- Name:
list-factory
- Type:
- Default Value:
- Flags:
The factory for populating list items in the popup.
If this is not set, [property`Gtk`.DropDown:factory] is used.
- Gtk.DropDown.props.model¶
- Name:
model
- Type:
- Default Value:
- Flags:
Model for the displayed items.
- Gtk.DropDown.props.search_match_mode¶
- Name:
search-match-mode
- Type:
- Default Value:
- Flags:
The match mode for the search filter.
New in version 4.12.
- Gtk.DropDown.props.selected¶
- Name:
selected
- Type:
- Default Value:
4294967295
- Flags:
The position of the selected item.
If no item is selected, the property has the value
Gtk.INVALID_LIST_POSITION
.
- Gtk.DropDown.props.selected_item¶
- Name:
selected-item
- Type:
- Default Value:
- Flags:
The selected item.
- Gtk.DropDown.props.show_arrow¶
- Name:
show-arrow
- Type:
- Default Value:
- Flags:
Whether to show an arrow within the
Gtk.DropDown
widget.New in version 4.6.