I want a button with text on it for a GtkListStore
. I read another answer using an image as a button, but I really need the title to be text. How can I do this? I'd be fine with a solution that renders text onto a GdkPixbuf
as well.
I've tried this:
GType *types;
types = g_new0 (GType, num_fields);
for(int i=0; i<num_fields; i++) {
types[i] = GTK_TYPE_BUTTON;
}
tree_store = gtk_list_store_newv(num_fields, types);
tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GdkPixbuf *icon;
renderer = gtk_cell_renderer_pixbuf_new();
column = gtk_tree_view_column_new_with_attributes (name.c_str(),renderer,"pixbuf",i,NULL);
button = gtk_button_new_with_label ("Quit");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
gtk_widget_set_can_default (button, TRUE);
gtk_list_store_set(tree_store, &iter, j, button, -1);
There are no errors, but nothing shows up.
I want to view the selection in a new window.
You have two options (actually you have more than two options, but you need to try the first two before I continue).
Hook up to the treeview "row_activated" signal, which can be set to single or double click. This will pass in the path to the selected row.
Put a button below/outside the treeview that gets a treeview "get_selected_row". You can then use this to get the content of the row you wish to open in a new window. Example. Hint: this is how Gtk recommends using buttons with a treeview.