Package: gtk

Class gtk-search-bar

Superclasses

gtk-bin, gtk-container, gtk-widget, gtk-buildable, g-object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

None

Direct Slots

search-mode-enabled
The search-mode-enabled property of type :boolean (Read / Write / Construct)
Whether the search mode is on and the search bar shown.
Default value: false
show-close-button
The show-close-button property of type :boolean (Read / Write / Construct)
Whether to show the Close button in the toolbar.
Default value: false

Details

gtk-search-bar is a container made to have a search entry built-in, possibly with additional connex widgets, such as drop-down menus, or buttons. 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, events will need to be forwarded from the toplevel window that contains the search bar. See the gtk-search-bar-handle-event function for example code. Common shortcuts such as the 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 the function gtk-search-bar-connect-entry. The following example shows you how to create a more complex search entry.

CSS nodes

gtk-search-bar has a single CSS node with name searchbar.

Example

Creating a search bar.
#include <gtk/gtk.h>

static gboolean window_key_press_event_cb (GtkWidget *window, GdkEvent *event, GtkSearchBar *search_bar) { return gtk_search_bar_handle_event (search_bar, event); }

static void activate_cb (GtkApplication *app, gpointer user_data) { GtkWidget *window; GtkWidget *search_bar; GtkWidget *box; GtkWidget *entry; GtkWidget *menu_button;

window = gtk_application_window_new (app); gtk_widget_show (window);

search_bar = gtk_search_bar_new (); gtk_container_add (GTK_CONTAINER (window), search_bar); gtk_widget_show (search_bar);

box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_container_add (GTK_CONTAINER (search_bar), box); gtk_widget_show (box);

entry = gtk_search_entry_new (); gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0); gtk_widget_show (entry);

menu_button = gtk_menu_button_new (); gtk_box_pack_start (GTK_BOX (box), menu_button, FALSE, FALSE, 0); gtk_widget_show (menu_button);

gtk_search_bar_connect_entry (GTK_SEARCH_BAR (search_bar), GTK_ENTRY (entry));

g_signal_connect (window, "key-press-event", G_CALLBACK (window_key_press_event_cb), search_bar); }

gint main (gint argc, gchar *argv[]) { GtkApplication *app;

app = gtk_application_new ("org.gtk.Example.GtkSearchBar", G_APPLICATION_FLAGS_NONE); g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);

return g_application_run (G_APPLICATION (app), argc, argv); }
 

Slot Access Functions

Inherited Slot Access Functions

2020-6-1