GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Dec 19, 2014 8:16 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: TreeView does not show anything
PostPosted: Sun Mar 01, 2009 8:09 pm 
Offline

Joined: Sun Mar 01, 2009 7:15 pm
Posts: 4
Location: Germany
Hello,

I have a problem with GTK TreeView. When I add rows to a TreeView,
the rows are added (the window on which the TreeView sits increases in
height), but I don't see the rows on screen :(. Here the part of my code,
that initializes the ListStore, and adds a test row:
Code:
enum {
  COLUMN_ATTRIBUTE = 0,
  COLUMN_VALUE,
  NUM_COLUMNS
};
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
GtkTreeIter iter;
GtkTreeView *tvBat1;
GtkListStore *storeBat1;

tvBat1 = GTK_TREE_VIEW(glade_xml_get_widget(gxml, "tvBat1"));

storeBat1 = gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model(tvBat1, GTK_TREE_MODEL(storeBat1));

column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(column, "Attribute");
gtk_tree_view_append_column(GTK_TREE_VIEW(tvBat1), column);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_add_attribute(column, renderer, "text", COLUMN_ATTRIBUTE);

column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(column, "Value");
gtk_tree_view_append_column(GTK_TREE_VIEW(tvBat1), column);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_add_attribute(column, renderer, "text", COLUMN_VALUE);

gtk_list_store_append(storeBat1, &iter);
gtk_list_store_set(storeBat1, &iter, COLUMN_ATTRIBUTE, "TestAttribute", COLUMN_VALUE, "TestValue", -1);
As you can see in the code, I create the GUI with Glade, so probably the error could also be in the Glade file.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 9:26 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the Gtk+ forums!

As far as I'm concerned, your code snippet is clean.

I created a stand-alone application to be compiled with slightly modified code from your post which works properly here. Try it and post back with the results (and maybe a glade file, if you think the problem lurks in it).

Code:
#include <gtk/gtk.h>

int
main( int    argc,
     char **argv )
{
   GtkWidget         *window;
   GtkWidget         *tree;
   GtkListStore      *store;
   GtkTreeViewColumn *column;
   GtkTreeIter        iter;
   GtkCellRenderer   *renderer;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   tree = gtk_tree_view_new();
   gtk_container_add( GTK_CONTAINER( window ), tree );

   column = gtk_tree_view_column_new();
   gtk_tree_view_column_set_title( column, "Attr" );
   gtk_tree_view_append_column( GTK_TREE_VIEW( tree ), column );
   renderer = gtk_cell_renderer_text_new();
   gtk_tree_view_column_pack_start( column, renderer, TRUE );
   gtk_tree_view_column_add_attribute( column, renderer, "text", 0 );

   column = gtk_tree_view_column_new();
   gtk_tree_view_column_set_title( column, "Val" );
   gtk_tree_view_append_column( GTK_TREE_VIEW( tree ), column );
   renderer = gtk_cell_renderer_text_new();
   gtk_tree_view_column_pack_start( column, renderer, TRUE );
   gtk_tree_view_column_add_attribute( column, renderer, "text", 1 );

   store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING );
   gtk_list_store_append( store, &iter );
   gtk_list_store_set( store, &iter, 0, "Test Attr", 1, "Test Val", -1 );

   gtk_tree_view_set_model( GTK_TREE_VIEW( tree ), GTK_TREE_MODEL( store ) );

   gtk_widget_show_all( window );

   gtk_main();

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 9:56 pm 
Offline

Joined: Sun Mar 01, 2009 7:15 pm
Posts: 4
Location: Germany
Hallo tadeboro,

thank you for your reply. Your code works, and displays the added row.
So the error must be in the Glade file.
The Glade file is too big to post it here, so I uploaded it to RapidShare:
http://rapidshare.com/files/204165730/Preferences.glade.html

_________________
The difference between genius and stupidity is; genius has its limits.
-Albert Einstein
Image


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 10:59 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

Looking at your glade file, my experiences tell me that fixed height mode of your tree views may be the problematic thingy in your glade file.

Try removing this option from your tree views and post the results.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 6:37 pm 
Offline

Joined: Sun Mar 01, 2009 7:15 pm
Posts: 4
Location: Germany
YES! This "fixed height mode" was it. Now it works. Thank you very much.

_________________
The difference between genius and stupidity is; genius has its limits.
-Albert Einstein
Image


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

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 2 guests


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