Want more features on Pastebin? Sign Up, it's FREE!
Guest

set position not working

By: a guest on Sep 28th, 2012  |  syntax: C  |  size: 2.55 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <gtk/gtk.h>
  2.  
  3. int main(int argc, char *argv[]) {
  4.     gtk_init(&argc, &argv);
  5.    
  6.     // Creating tree view stuff
  7.     GtkListStore *store1 = gtk_list_store_new(1, G_TYPE_STRING),
  8.                  *store2 = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING);
  9.    
  10.     GtkWidget *tree_view1 = gtk_tree_view_new(),
  11.               *tree_view2 = gtk_tree_view_new();
  12.    
  13.     gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view1), GTK_TREE_MODEL(store1));
  14.     gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view2), GTK_TREE_MODEL(store2));
  15.    
  16.     // Creating columns
  17.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view1),
  18.             -1, "Left", gtk_cell_renderer_text_new(),
  19.             "text", 0, NULL);
  20.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view2),
  21.             -1, "Number", gtk_cell_renderer_text_new(),
  22.             "text", 0, NULL);
  23.     gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree_view2),
  24.             -1, "Right", gtk_cell_renderer_text_new(),
  25.             "text", 1, NULL);
  26.  
  27.     // Populating models
  28.     GtkTreeIter iter;
  29.     gtk_list_store_append(store1, &iter);
  30.     gtk_list_store_set(store1, &iter, 0, "left 1", -1);
  31.     gtk_list_store_append(store1, &iter);
  32.     gtk_list_store_set(store1, &iter, 0, "left 2", -1);
  33.    
  34.     gtk_list_store_append(store2, &iter);
  35.     gtk_list_store_set(store2, &iter, 0, 42);
  36.     gtk_list_store_set(store2, &iter, 1, "right 1", -1);
  37.     gtk_list_store_append(store2, &iter);
  38.     gtk_list_store_set(store2, &iter, 0, 13);
  39.     gtk_list_store_set(store2, &iter, 1, "right 2", -1);
  40.     gtk_list_store_append(store2, &iter);
  41.     gtk_list_store_set(store2, &iter, 0, 9);
  42.     gtk_list_store_set(store2, &iter, 1, "right 3", -1);
  43.    
  44.     // Packing together
  45.     GtkWidget *paned = gtk_hpaned_new();
  46.     GtkWidget *scrolled_window1 = gtk_scrolled_window_new(NULL, NULL),
  47.               *scrolled_window2 = gtk_scrolled_window_new(NULL, NULL);
  48.     gtk_container_add(GTK_CONTAINER(scrolled_window1), tree_view1);
  49.     gtk_container_add(GTK_CONTAINER(scrolled_window2), tree_view2);
  50.     gtk_paned_add1(GTK_PANED(paned), scrolled_window1);
  51.     gtk_paned_add2(GTK_PANED(paned), scrolled_window2);
  52.    
  53.     GtkRequisition req;
  54.     gtk_widget_size_request(tree_view1, &req);  // get tree's preferred size
  55.     gtk_paned_set_position(GTK_PANED(paned), req.width);
  56.        
  57.     GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  58.     gtk_container_add(GTK_CONTAINER(window), paned);
  59.    
  60.     gtk_widget_show_all(window);
  61.    
  62.     gtk_main();
  63.    
  64.     return 0;
  65. }
clone this paste RAW Paste Data