GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Apr 20, 2014 3:54 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: TreeView : no scroller
PostPosted: Tue May 13, 2008 4:00 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Please help.

I am setting up a Treeview (see code) and in the SETUP section
I am adding vertical scroller. I doing obviously something wrong
because the scroller never shows up, even if the list is very long in the
treeview.
Please, anyone can help?
Peter
Code:
void SignalTree(GtkWidget *window, int r) {
   static GtkListStore *store;
   static GtkTreeIter iter;
   static GtkWidget *treeview, *scrolled_win;
   static GtkCellRenderer *renderer;
   static GtkTreeViewColumn *column;
   static GtkTreeSelection *selection;
   static GtkTreeModel *model;
   int i, j, R, Ndata, click = 0, n;
   gchar edtext[80];

      treeview = lookup_widget (window, "Signaltree");
      model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
      Ndata = sizeof(SigNames)/sizeof(SigNames[0]);

      if (r==STARTUP) {
         NumSignals = 0;      
         NumSelSignals = 0;

               
         store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Signal", renderer, "text", SIGNAME_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);

        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
         //   gtk_tree_view_column_set_expand (GtkTreeViewColumn, column, TRUE);
        
        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Selected", renderer, "text", SIGUNIT_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);

        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
         //gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
         gtk_tree_selection_set_mode ( selection, GTK_SELECTION_MULTIPLE );

         // insert content
         for (j = 0; j < 5; j++) {
            for (i = 0; i < Ndata; i++) {
               NumSignals++;
               /* Add a new row to the model */
             gtk_list_store_append (store, &iter);
            gtk_list_store_set (store, &iter, SIGNAME_COLUMN, SigNames[i], -1);
               gtk_list_store_set (store, &iter, SIGUNIT_COLUMN, UnitNames[i], -1);

             }  // i
         } // j
         
         // the scroller:
         scrolled_win = gtk_scrolled_window_new(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_win), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
         gtk_container_add(GTK_CONTAINER(scrolled_win), treeview);
         gtk_container_add(GTK_CONTAINER(window), scrolled_win);
      
   } else if (r==REFRESH ){  // generate in random order
      gtk_list_store_clear (store);
    //....do something else
   } else if (r==APPEND) {
      n = 0;
      gtk_list_store_clear (store);
   } else if (r==CLEAR) {
      gtk_list_store_clear (store);
      NumSelSignals = 0;
   }
   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
   gtk_widget_show_all(treeview);
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 4:10 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Change this line:

Code:
scrolled_win = gtk_scrolled_window_new(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));


to this;
Code:
scrolled_win = gtk_scrolled_window_new(NULL, NULL);


Essentially, when adding a GtkTreeView widget to a GtkScrolledWindow you don't need to worry about the GtkAdjustments, it happens automatically through magic. Or, more precisely, from the manual...

Quote:
The scrolled window can work in two ways. Some widgets have native scrolling support; these widgets have "slots" for GtkAdjustment objects. [5] Widgets with native scroll support include GtkTreeView, GtkTextView, and GtkLayout.


and...

Quote:
The two arguments are the scrolled window's adjustments; these will be shared with the scrollbars and the child widget to keep the bars in sync with the child. Usually you want to pass NULL for the adjustments, which will cause the scrolled window to create them for you.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 5:32 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah Carrick wrote:
Change this line:

Code:
scrolled_win = gtk_scrolled_window_new(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));


to this;
Code:
scrolled_win = gtk_scrolled_window_new(NULL, NULL);


Essentially, when adding a GtkTreeView widget to a GtkScrolledWindow you don't need to worry about the GtkAdjustments, it happens automatically through magic. Or, more precisely, from the manual...

Quote:
The scrolled window can work in two ways. Some widgets have native scrolling support; these widgets have "slots" for GtkAdjustment objects. [5] Widgets with native scroll support include GtkTreeView, GtkTextView, and GtkLayout.


and...

Quote:
The two arguments are the scrolled window's adjustments; these will be shared with the scrollbars and the child widget to keep the bars in sync with the child. Usually you want to pass NULL for the adjustments, which will cause the scrolled window to create them for you.


STILL NO SHOW.
When I ran the program with the change you suggested I get this runtime message:
[code=]
(codes:14656): Gtk-WARNING **: Attempting to add a widget with type GtkTreeView to a container of type GtkScrolledWindow, but the widget is already inside a container of type GtkFixed, the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget.

(codes:14656): Gtk-WARNING **: Attempting to add a widget with type GtkScrolledWindow to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkFixed


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 5:44 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Oh... I wasn't looking that closely. You are using Glade right?

You need to put the treeview widget into a scrolled window from within Glade.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 7:38 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah Carrick wrote:
Oh... I wasn't looking that closely. You are using Glade right?

You need to put the treeview widget into a scrolled window from within Glade.

Micah, thanks!
Yes, when I added the scroller in Glade, things worked. I did not need to add
the gtk_container_add() lines in the code somehow it added the scrollbar to the
container automatically.
Thanks once again.
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 7:50 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Yes, the GtkTreeView has "slots" for scrollers automatically. When you add a GtkTreeView (or GtkTextView) to a GtkScrolledWindow--be it through Glade or through code--the scrolling functionality will be handled automatically from that point.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group