用于将搜索栏添加到GTK3应用程序(在C中)。我正在使用以下方法:
pad->priv->searchbar = GTK_SEARCH_BAR (gtk_search_bar_new ());
gtk_search_bar_set_show_close_button (pad->priv->searchbar, TRUE);
GtkSearchEntry *searchentry = GTK_SEARCH_ENTRY (gtk_search_entry_new ());
gtk_container_add (GTK_CONTAINER (pad->priv->searchbar),
GTK_WIDGET (searchentry));
/* Below does nothing (I mean haligh/valigh*/
// (meant to put searchentry with no more free space in search_bar
// (to the left)
// I could also add a label Find but what for? I just want
// GtkSearchEntry to occupy the whole GtkSearchBar apart for close btn
/* Nothing of that works */
//gtk_widget_set_halign (GTK_WIDGET (searchentry), GTK_ALIGN_START);
//gtk_widget_set_valign (GTK_WIDGET (searchentry), GTK_ALIGN_START);
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (pad->priv->searchbar),
GTK_ENTRY (searchentry));
// Searchbar should appear in right-top corner of the overlay
// to not cover the text which is searched (assuming that first
// several lines most probably are short enough to not be covered)
/* So these line do work but only for the GtkSearchBar itself
not got GtkSearchEntry inside of it) (/
gtk_widget_set_halign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_END);
gtk_widget_set_valign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_START);
// Jere a Just add a scroll with a text and a GtkSearchBar to a GtkOverlay
pad->priv->text_with_search_overlay = GTK_OVERLAY (gtk_overlay_new ());
gtk_overlay_add_overlay (pad->priv->text_with_search_overlay, pad->priv->scrollbar);
gtk_overlay_add_overlay (pad->priv->text_with_search_overlay, GTK_WIDGET (pad->priv->searchbar));
这很好用。我只是无法自定义gtk_search_bar。我不是要使用gtk_search_bar并在叠加层中创建自己的vbox来实现此目的吗?这样,将根本没有gtk_search_bar,只有我的带有gtk_search_entry的小部件带有一个按钮,然后手动将其删除。
现在可以观察到的是:https://imagebin.ca/v/4Uo7Bqi6Pv7J。我不喜欢GtkSearchBar左上角的空白区域。它是可定制的还是我必须编写自己的搜索栏(例如带有内容的HBox)。我可以通过创建Hbox,添加GtkSearchEnttry和关闭按钮来摆脱它。但是它将删除显示/隐藏它的便捷功能:gtk_search_bar_set_search_mode-TRUE / FALSE,我喜欢它的存在
是否可以通过某种方式“样式化” GtkSearchBar。也许在这里:
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (pad->priv->searchbar), GTK_ENTRY (searchentry)); ?
我正在尝试对gtk_search_bar使用halign / valign:
gtk_widget_set_halign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_END);
gtk_widget_set_valign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_START);
但是对gtk_search_entry这样做:
gtk_widget_set_halign (GTK_WIDGET (searchentry), GTK_ALIGN_END);
gtk_widget_set_valign (GTK_WIDGET (searchentry), GTK_ALIGN_START);
什么都不做
这适用于GtkSearchBsr。如何用于gtk_search_bar内的元素?还有其他方法可以手动创建其布局吗?