GtkTreeView doesn't refresh
- From: Jarosław Sobieszek <j sobieszek neo pl>
- To: <gtk-app-devel-list gnome org>
- Subject: GtkTreeView doesn't refresh
- Date: Wed, 27 Nov 2013 11:57:57 +0000
Hello,
I'm trying to dynamically modify list based on some action. Program below
should add 3 rows at the top and 3 rows at the bottom of the list for every
click of the button. For some reason it doesn't work - I'm seeing partial
updates with random amount of data (only 2 top rows on first click, then 5
at the bottom, on 3rd click the list looks ok (9 rows added at the top and
9 rows added at the bottom)). I've tested this under gtk2 and it works ok.
Am I missing something or is it a bug in gtk3 (gtk3-3.8.6 under Fedora 19)?
Thank you,
Jarek
--- test_list.c ---
#include <gtk/gtk.h>
void on_click(GtkButton *b, gpointer data) {
GtkListStore *store = GTK_LIST_STORE(data);
int i;
for (i = 0; i < 3; i++) {
GtkTreeIter it;
gchar entry[256];
gtk_list_store_prepend(store, &it);
g_snprintf(entry, 256, "olleH%d", i);
gtk_list_store_set(store, &it, 0, 321, 1, entry, -1);
}
for (i = 0; i < 3; i++) {
GtkTreeIter it;
gchar entry[256];
gtk_list_store_append(store, &it);
g_snprintf(entry, 256, "Hello%d", i);
gtk_list_store_set(store, &it, 0, 123, 1, entry, -1);
}
}
gboolean on_delete(GtkWidget *w, GdkEvent *e, gpointer data) {
gtk_main_quit();
}
int main(int argc, char *argv[]) {
GtkWidget *w;
GtkWidget *box;
GtkListStore *store;
GtkCellRenderer *renderer1, *renderer2;
GtkTreeViewColumn *column1, *column2;
GtkWidget *tree;
GtkWidget *b;
int i;
gtk_init(&argc, &argv);
w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(w), box);
store = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
for (i = 0; i < 10; i++) {
GtkTreeIter it;
gchar entry[256];
gtk_list_store_append(store, &it);
g_snprintf(entry, 256, "Entry %d", i + 1);
gtk_list_store_set(store, &it, 0, i + 1, 1, entry, -1);
}
tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
renderer1 = gtk_cell_renderer_text_new();
column1 = gtk_tree_view_column_new_with_attributes("Num", renderer1,
"text", 0, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);
renderer2 = gtk_cell_renderer_text_new();
column2 = gtk_tree_view_column_new_with_attributes("Entry", renderer2,
"text", 1, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column2);
gtk_container_add(GTK_CONTAINER(box), tree);
b = gtk_button_new_with_label("Click here");
g_signal_connect(b, "clicked", G_CALLBACK(on_click), store);
gtk_container_add(GTK_CONTAINER(box), b);
g_signal_connect(w, "delete-event", G_CALLBACK(on_delete), NULL);
gtk_widget_show_all(w);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]