[Glade-devel] glade: populating table/list with headers



On Sat, 2011-11-12 at 20:29 +0100, Saku Masukita wrote:

Hello,

I need to populate a list/table in glade with some headers
which label the columns. Could anyone point me in the
right direction. Do I need to use a GtkTreeView? Is the
old CList no longer supported for this? Do I have to
build my own custom widget and import it into glade?

Hi Saku,
   If you are displaying dynamic content, and that content
might be larger than say, 5 or 10 rows of data... then you
should definitely use a GtkTreeView.

Note that the ultimate problem with the old clist widgets
was that they use an unreasonable amount of resources to
display a list of dynamic data, so you do not want to relive
that by creating widgets for each row yourself (once you have
around 100 rows it can start to take a long time just to create
those widgets).

To do this in Glade,
  o Create a GtkTreeView
  o Create a GtkListStore (it may be an option while creating the view)
  o Then select the "Edit" toolbar item with the treeview selected
  o In the main page... assign data types to your list store,
    for instance you might have a column named 'name' which is
    of type 'gchararray' (GType-speak for a string)
  o Then go to the 'Hierarchy' tab of the editor
  o Press the 'Add' button on the bottom left, this will add
    a GtkTreeViewColumn to your view
  o Right Click on the newly created treeview column which appears
    in the treeview editor window
  o In this context menu you can create GtkCellRenderers to show
    data in your view... Add some renderers, a text renderer to
    render text, etc.
  o Now that you have a renderer selected, on the right hand you
    will have a list of properties... only here instead of strict
    values (which are still possible), you can attribute the cell
    renderer properties to be set from specific values in the 
    GtkTreeStore which you defined earlier

    So in this final step, you say that the GtkCellRendererText:text
    property should be driven by the 'name' column which you defined
    in your GtkTreeStore as a 'gchararray' (string).

After that, in code you generally have a loop where you call
apis like gtk_list_store_append() to add the data you need.

Cheers,
         -Tristan






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]