For adding search bar to the GTK3 app (in C). I'm using the following cooe:
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));
This works nicely. I'm just not able to customize gtk_search_bar. Do I have not yo use gtk_search_bar and create my own vbox in the overlay for this to happen? This way there will be no gtk_search_bar at all, just my widget with gtk_search_entry an button, manually removing it.
Whas it now can be observed: https://imagebin.ca/v/4Uo7Bqi6Pv7J. I don't like empty space in the left corner of the GtkSearchBar. Is it customizable or do I have to write my own search bar (like HBox with stuff). I can get rid of it by creating a Hbox,adding GtkSearchEnttry and a close button. But it will remove convenient function to show/hide it: gtk_search_bar_set_search_mode - TRUE/FALSE and I like that it exists
Is there a way to "style" the GtkSearchBar somehow. Maybe here:
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (pad->priv->searchbar), GTK_ENTRY (searchentry)); ?
I'm doing trying to use halign/valign for the gtk_search_bar:
gtk_widget_set_halign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_END);
gtk_widget_set_valign (GTK_WIDGET (pad->priv->searchbar), GTK_ALIGN_START);
But doing so for gtk_search_entry:
gtk_widget_set_halign (GTK_WIDGET (searchentry), GTK_ALIGN_END);
gtk_widget_set_valign (GTK_WIDGET (searchentry), GTK_ALIGN_START);
does nothing
This works for GtkSearchBsr. how to use for elements inside gtk_search_bar? Is there other way then create their layout by hand?
Related
i want to change default close, maximize, minimize buttons' icon. So i need to get default buttons.
In gtk3, i used gtk_header_bar_set_show_close_button to enable default button, and used gtk_container_get_children(header_bar) to get children widget
GtkWidget *header_bar = gtk_header_bar_new();
gtk_header_bar_set_has_subtitle(GTK_HEADER_BAR(header_bar), FALSE);
gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header_bar), TRUE);
gtk_window_set_titlebar(GTK_WINDOW(window), header_bar);
GList *children = gtk_container_get_children(header_bar);
if(children == NULL) {
exit(-1);
}
GList *children always is NULL.
How can I get it like gtk inspector?
gtk inscpector screenshot
Resolve:
should use gtk_container_forall to get "internal" children
I am using a Gtk EventBox which holds an image to receive mouse click events on the image. Once the image is clicked, the EventBox is set insensitive. However, since this results in the EventBox being "grayed out", the colors of my image become pale as well. I really don't like this. Is there any way to disable this kind of behaviour of Gtk widgets?
Code example:
var ebox = new EventBox ();
var img = new Image ();
img.set_from_file ("my_image.png");
img.show ();
ebox.add (img);
ebox.button_press_event.connect ( () => { ebox.set_sensitive (false); return true; } );
you could subclass the widget, add a virtual method do_draw(), and draw your image there.
I have a treeview that uses GtkCellRendererToggle to display toggle buttons inside cells. My question: Is is possible to set the color just for the toggle button there? I only know how to set the cell background, which is done like this:
g_object_set (toggle-renderer, "cell-background",
"anycolouryoulike", "cell-background-set", TRUE, NULL);
GtkCellRenderer features only cell background properties, I wonder if there is nethertheless a way to do it? (I use C, but if there is a way, an example in any language would do).
GtkCssProvider might help, just try to style buttons within GtkCssProvider (list of suported properties per widget , not necessary for this case)
You could use something like
#supercolorme {
color: #ffed00;
}
and name your widgets supercolorme by using
void gtk_widget_set_name (GtkWidget *widget, const gchar *name); as described in the gtk+ API docs
I have this code which sets up a "main" container into which other modules of the application will go.
LayoutContainer c = new LayoutContainer();
c.setScrollMode(Scroll.ALWAYS);
parentContainer.add(c, <...>);
Then later on, I have the following as an event handler
pContainer = c; // pContainer is actually a parameter, but it has c's value
pContainer.removeAll();
pContainer.setLayout(new FitLayout());
LayoutContainer wrapperContainer = new LayoutContainer();
wrapperContainer.setLayout(new BorderLayout());
wrapperContainer.setBorders(false);
pContainer.add(wrapperContainer);
LayoutContainer west = pWestContentContainer;
BorderLayoutData westLayoutData = new BorderLayoutData(LayoutRegion.WEST);
westLayoutData.setSize(pWidth);
westLayoutData.setSplit(true);
wrapperContainer.add(west, westLayoutData);
LayoutContainer center = new LayoutContainer();
wrapperContainer.add(center, new BorderLayoutData(LayoutRegion.CENTER));
pCallback.withSplitContainer(center);
pContainer.layout();
So in effect, the container called 'west' here will be where the module's UI gets displayed. That module UI then does a simple rowlayout with two children. The botton child has RowData(1, 1) so it fills up all the available space.
My problem is that the c (parent) container reports a height and width value which includes the value underneath the scrollbars. What I would like is that the scrollbars show all the space excluding their own space.
This is a screenshot showing what I mean:
alt text http://img265.imageshack.us/img265/9206/scrollbar.png
Try adding padding equivalent to the scroll bars size 14px? on the container where the Scroll.Always is being applied
I have a crossplatform app that has a gtk.StatusIcon sitting in the tray, and a right click context menu. The problem is: on Windows machines the placement of the menu is awful. The top of the menu starts at the mouse pointer and so most of the menu extends below the bottom of the screen. This can then be scrolled up and is usable, but it is a bit of a pain for the user.
Another related question, is it possible to make the menu disappear if the user clicks somewhere else on the screen?
To avoid this "scrolling menu" problem on Windows you need to replace gtk.status_icon_position_menu with None in "popup-menu" signal callback.
def popup_menu_cb(status_icon, button, activate_time, menu):
menu.popup(None, None, None, button, activate_time)
The menu will show on the mouse cursor but that's how all windows programs do it.
Don't know how to hide it though... the only thing I found to work is pressing a mouse button on the menu and releasing it outside. :P
You can hide the popup when the mouse moves away by enabling the leave_notify and enter_notify events on the popup. Then use these to set and clear a time stamp. Then in a timer callback created with gobject.timeout_add() check to see if the mouse has been away from the popup menu for a certain amount of time. If it has then hide() the popup and clear the timer.
Here are the event and timer call backs I'm using:
. . .
self.mouse_in_tray_menu = None
gobject.timeout_add(500, self.check_hide_popup)
. . .
def on_tray_menu_enter_notify_event(self, widget, event, data = None):
self.mouse_in_tray_menu = None
def on_tray_menu_leave_notify_event(self, widget, event, data = None):
self.mouse_in_tray_menu = event.time + 1 # Timeout in 1 sec
def check_hide_popup(self, data = None):
if self.mouse_in_tray_menu and self.mouse_in_tray_menu < time.time():
self.tray_menu.hide()
self.mouse_in_tray_menu = None
return True # Keep the timer callback running
You don't have to keep the timer running all the time but it is easier and I am also using it for other things. The calls to enter_notify and leave_notify are somewhat erratic so the timer is necessary.
BTW, this is really only necessary in Windows because in Linux you can click elsewhere and the popup will close.
I found a solution to fix the popup menu won't hide problem on windows.
Just add following code (my code is in C but you can change it to python or whatever) before popping up the menu:
GtkWidget *hidden_window;
hidden_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (hidden_window), FALSE);
gtk_window_set_decorated (GTK_WINDOW (hidden_window), FALSE);
gtk_window_set_skip_taskbar_hint (GTK_WINDOW (hidden_window), TRUE);
gtk_window_set_skip_pager_hint (GTK_WINDOW (hidden_window), TRUE);
gtk_widget_set_size_request (hidden_window, 0, 0);
gtk_window_set_transient_for (GTK_WINDOW (hidden_window), GTK_WINDOW (widget)); //widget is your main window, this is to hide dummy window from taskbar
gtk_window_set_position (GTK_WINDOW (hidden_window), GTK_WIN_POS_MOUSE);
gtk_widget_set_events (hidden_window, GDK_FOCUS_CHANGE_MASK);
g_signal_connect (G_OBJECT (hidden_window),
"focus-out-event",
G_CALLBACK (on_hidden_window_focus_out),
NULL);
gtk_widget_show_all (hidden_window);
gtk_widget_grab_focus (hidden_window);
also add this function:
static void on_hidden_window_focus_out(GtkWidget *widget,
GdkEventFocus *event,
gpointer data)
{
gtk_widget_destroy (widget);
}
The idea is to create a 1x1 top level window at mouse position and grab the focus, and add destroy function when focus out.