GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TreeView : no scroller

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Peter
GTK+ Geek


Joined: 10 May 2008
Posts: 54

PostPosted: Tue May 13, 2008 4:00 pm    Post subject: TreeView : no scroller Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

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);
}
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Tue May 13, 2008 4:10 pm    Post subject: Reply with quote

Change this line:

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


to this;
Code: (C)
1
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.
Back to top
Peter
GTK+ Geek


Joined: 10 May 2008
Posts: 54

PostPosted: Tue May 13, 2008 5:32 pm    Post subject: Reply with quote

Micah Carrick wrote:
Change this line:

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


to this;
Code: (C)
1
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: (Plaintext)
1
2
3
4
5
6
7

(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


Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Tue May 13, 2008 5:44 pm    Post subject: Reply with quote

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.
Back to top
Peter
GTK+ Geek


Joined: 10 May 2008
Posts: 54

PostPosted: Tue May 13, 2008 7:38 pm    Post subject: Reply with quote

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
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 495
Location: Portland, OR USA

PostPosted: Tue May 13, 2008 7:50 pm    Post subject: Reply with quote

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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP