GtkSearchBar — A toolbar to integrate a search entry with
GtkWidget * | gtk_search_bar_new () |
void | gtk_search_bar_set_child () |
GtkWidget * | gtk_search_bar_get_child () |
void | gtk_search_bar_connect_entry () |
gboolean | gtk_search_bar_get_search_mode () |
void | gtk_search_bar_set_search_mode () |
gboolean | gtk_search_bar_get_show_close_button () |
void | gtk_search_bar_set_show_close_button () |
void | gtk_search_bar_set_key_capture_widget () |
GtkWidget * | gtk_search_bar_get_key_capture_widget () |
GtkWidget * | child | Read / Write / Construct |
GtkWidget * | key-capture-widget | Read / Write / Construct |
gboolean | search-mode-enabled | Read / Write |
gboolean | show-close-button | Read / Write / Construct |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkSearchBar
GtkSearchBar implements GtkAccessible, GtkBuildable and GtkConstraintTarget.
#include <gtk/gtk.h>
GtkSearchBar is a container made to have a search entry (possibly with additional connex widgets, such as drop-down menus, or buttons) built-in. The search bar would appear when a search is started through typing on the keyboard, or the application’s search mode is toggled on.
For keyboard presses to start a search, the search bar must be told of a widget to capture key events from through gtk_search_bar_set_key_capture_widget()
. This widget will typically be the top-level window, or a parent container of the search bar. Common shortcuts such as Ctrl+F should be handled as an application action, or through the menu items.
You will also need to tell the search bar about which entry you are using as your search entry using gtk_search_bar_connect_entry()
. The following example shows you how to create a more complex search entry.
searchbar ╰── revealer ╰── box ├── [child] ╰── [button.close]
GtkSearchBar has a main CSS node with name searchbar. It has a child node with name revealer that contains a node with name box. The box node contains both the CSS node of the child widget as well as an optional button node which gets the .close style class applied.
GtkSearchBar uses the GTK_ACCESSIBLE_ROLE_SEARCH
role.
GtkWidget *
gtk_search_bar_new (void
);
Creates a GtkSearchBar. You will need to tell it about which widget is going to be your text entry using gtk_search_bar_connect_entry()
.
a new GtkSearchBar
void gtk_search_bar_set_child (GtkSearchBar *bar
,GtkWidget *child
);
Sets the child widget of bar
.
bar | ||
child | the child widget. | [allow-none] |
GtkWidget *
gtk_search_bar_get_child (GtkSearchBar *bar
);
Gets the child widget of bar
.
bar |
the child widget of bar
.
[nullable][transfer none]
void gtk_search_bar_connect_entry (GtkSearchBar *bar
,GtkEditable *entry
);
Connects the GtkEntry widget passed as the one to be used in this search bar. The entry should be a descendant of the search bar. This is only required if the entry isn’t the direct child of the search bar (as in our main example).
bar | ||
entry |
gboolean
gtk_search_bar_get_search_mode (GtkSearchBar *bar
);
Returns whether the search mode is on or off.
bar |
whether search mode is toggled on
void gtk_search_bar_set_search_mode (GtkSearchBar *bar
,gboolean search_mode
);
Switches the search mode on or off.
bar | ||
search_mode | the new state of the search mode |
gboolean
gtk_search_bar_get_show_close_button (GtkSearchBar *bar
);
Returns whether the close button is shown.
bar |
whether the close button is shown
void gtk_search_bar_set_show_close_button (GtkSearchBar *bar
,gboolean visible
);
Shows or hides the close button. Applications that already have a “search” toggle button should not show a close button in their search bar, as it duplicates the role of the toggle button.
bar | ||
visible | whether the close button will be shown or not |
void gtk_search_bar_set_key_capture_widget (GtkSearchBar *bar
,GtkWidget *widget
);
Sets widget
as the widget that bar
will capture key events from.
If key events are handled by the search bar, the bar will be shown, and the entry populated with the entered text.
bar | ||
widget | a GtkWidget. | [nullable][transfer none] |
GtkWidget *
gtk_search_bar_get_key_capture_widget (GtkSearchBar *bar
);
Gets the widget that bar
is capturing key events from.
bar |
The key capture widget.
[transfer none]
typedef struct _GtkSearchBar GtkSearchBar;
“child”
property“child” GtkWidget *
The child widget.
Owner: GtkSearchBar
Flags: Read / Write / Construct
“key-capture-widget”
property“key-capture-widget” GtkWidget *
Key Capture Widget.
Owner: GtkSearchBar
Flags: Read / Write / Construct
“search-mode-enabled”
property“search-mode-enabled” gboolean
Whether the search mode is on and the search bar shown.
See gtk_search_bar_set_search_mode()
for details.
Owner: GtkSearchBar
Flags: Read / Write
Default value: FALSE
“show-close-button”
property“show-close-button” gboolean
Whether to show the close button in the search bar.
Owner: GtkSearchBar
Flags: Read / Write / Construct
Default value: FALSE
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkSearchBar.html