Gtk.SearchEntry¶
class — extends Widget, Accessible, Buildable, ConstraintTarget, Editable
A single-line text entry widget for use as a search entry.
The main API for interacting with a GtkSearchEntry as entry
is the GtkEditable interface.
<picture> <source srcset="search-entry-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkSearchEntry" src="search-entry.png"> </picture>
It will show an inactive symbolic “find” icon when the search entry is empty, and a symbolic “clear” icon when there is text. Clicking on the “clear” icon will empty the search entry.
To make filtering appear more reactive, it is a good idea to
not react to every change in the entry text immediately, but
only after a short delay. To support this, GtkSearchEntry
emits the SearchEntry.search-changed signal which
can be used instead of the Editable.changed signal.
The SearchEntry.previous-match,
SearchEntry.next-match and
SearchEntry.stop-search signals can be used to
implement moving between search results and ending the search.
Often, GtkSearchEntry will be fed events by means of being
placed inside a SearchBar. If that is not the case,
you can use SearchEntry.set_key_capture_widget to
let it capture key input from another widget.
GtkSearchEntry provides only minimal API and should be used with
the Editable API.
Shortcuts and Gestures¶
The following signals have default keybindings:
CSS Nodes¶
GtkSearchEntry has a single CSS node with name entry that carries
a .search style class, and the text node is a child of that.
Accessibility¶
GtkSearchEntry uses the AccessibleRole.search_box role.
Constructors¶
new¶
Creates a GtkSearchEntry.
Methods¶
get_input_hints¶
Gets the input purpose for entry.
get_input_purpose¶
Gets the input purpose of entry.
get_key_capture_widget¶
Gets the widget that entry is capturing key events from.
get_placeholder_text¶
Gets the placeholder text associated with entry.
get_search_delay¶
Get the delay to be used between the last keypress and the
SearchEntry.search-changed signal being emitted.
set_input_hints¶
Sets the input hints for entry.
Parameters:
hints— the new input hints
set_input_purpose¶
Sets the input purpose of entry.
Parameters:
purpose— the new input purpose
set_key_capture_widget¶
Sets widget as the widget that entry will capture key
events from.
Key events are consumed by the search entry to start or continue a search.
If the entry is part of a GtkSearchBar, it is preferable
to call SearchBar.set_key_capture_widget instead,
which will reveal the entry in addition to triggering the
search entry.
Note that despite the name of this function, the events
are only 'captured' in the bubble phase, which means that
editable child widgets of widget will receive text input
before it gets captured. If that is not desired, you can
capture and forward the events yourself with
EventControllerKey.forward.
Parameters:
widget— aGtkWidget
set_placeholder_text¶
Sets the placeholder text associated with entry.
Parameters:
text— the text to set as a placeholder
set_search_delay¶
Set the delay to be used between the last keypress and the
SearchEntry.search-changed signal being emitted.
Parameters:
delay— a delay in milliseconds
Properties¶
activates_default¶
Whether to activate the default widget when Enter is pressed.
input_hints¶
The hints about input for the GtkSearchEntry used to alter the
behaviour of input methods.
input_purpose¶
The purpose for the GtkSearchEntry input used to alter the
behaviour of input methods.
key_capture_widget¶
The widget that the entry will use to capture key events.
Key events are consumed by the search entry to start or continue a search.
placeholder_text¶
The text that will be displayed in the GtkSearchEntry
when it is empty and unfocused.
search_delay¶
The delay in milliseconds from last keypress to the search changed signal.
Signals¶
activate¶
Emitted when the entry is activated.
The keybindings for this signal are all forms of the <kbd>Enter</kbd> key.
next-match¶
Emitted when the user initiates a move to the next match for the current search string.
This is a keybinding signal.
Applications should connect to it, to implement moving between matches.
The default bindings for this signal is <kbd>Ctrl</kbd>+<kbd>g</kbd>.
previous-match¶
Emitted when the user initiates a move to the previous match for the current search string.
This is a keybinding signal.
Applications should connect to it, to implement moving between matches.
The default bindings for this signal is <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>g</kbd>.
search-changed¶
Emitted with a delay. The length of the delay can be
changed with the SearchEntry.search-delay
property.
search-started¶
Emitted when the user initiated a search on the entry.
stop-search¶
Emitted when the user stops a search via keyboard input.
This is a keybinding signal.
Applications should connect to it, to implement hiding the search entry in this case.
The default bindings for this signal is <kbd>Escape</kbd>.