Re: Scrolling a GtkTreeview cell
- From: cecashon aol com
- To: kian karas dev gmail com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Scrolling a GtkTreeview cell
- Date: Thu, 25 Jan 2018 13:36:57 -0500
Hi Kian,
A list box is more flexible for allowing different widgets but the performance might not be so good if you
have a lot of rows. Don't have the numbers to show that though.
You can put your individual widgets into a scrolled window if you want. The scroll bars will show if the
content runs past the border. This is a little test code with some textviews in scrolled windows within the
list box. You can move across rows and columns with the keyboard arrow keys. Might have to do a little
programming to get the list box to behave how you want for your program.
Eric
/*
gcc -Wall list_box1.c -o list_box1 `pkg-config --cflags --libs gtk+-3.0`
Tested on Ubuntu16.04 and GTK3.18
*/
#include<gtk/gtk.h>
static GtkWidget *create_row(const gchar *text)
{
GtkWidget *row=gtk_list_box_row_new();
gtk_widget_set_size_request(row, 370, 50);
gtk_list_box_row_set_selectable(GTK_LIST_BOX_ROW(row), TRUE);
gtk_list_box_row_set_activatable(GTK_LIST_BOX_ROW(row), TRUE);
GtkWidget *textview=gtk_text_view_new();
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_CHAR);
gtk_widget_set_hexpand(textview, TRUE);
gtk_widget_set_vexpand(textview, TRUE);
GtkTextBuffer *buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
gtk_text_buffer_set_text(buffer, text, -1);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), textview);
GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_set_border_width(GTK_CONTAINER(box), 5);
g_object_set (box, "margin-end", 10, NULL);
GtkWidget *label=gtk_label_new(text);
gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(row), box);
return row;
}
int main(int argc, char **argv)
{
gtk_init(&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "List Box");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GtkWidget *list_box=gtk_list_box_new();
gtk_list_box_set_activate_on_single_click(GTK_LIST_BOX(list_box), TRUE);
gtk_widget_set_hexpand(list_box, TRUE);
gtk_widget_set_vexpand(list_box, TRUE);
gint i=0;
GtkWidget *row=NULL;
for(i=0;i<10;i++)
{
gchar *text=g_strdup_printf("Row %d", i);
row=create_row(text);
gtk_list_box_insert(GTK_LIST_BOX(list_box), row, -1);
g_free(text);
}
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_widget_set_hexpand(scroll, TRUE);
gtk_widget_set_vexpand(scroll, TRUE);
gtk_container_add(GTK_CONTAINER(scroll), list_box);
GtkWidget *grid1=gtk_grid_new();
gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
gtk_grid_attach(GTK_GRID(grid1), scroll, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid1);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]