0

I'm making a GUI application with gtk2hs. Most of the GUI is designed in Glade. I now need a table to show some data. The problem is, that I can't find the table in glade. I searched in the Container category, but only found a "Grid". However I couldn't find a Grid in the documentation of gtk2hs, but I need the castTo* function for the grid to use it.

I'm now wondering where the Table in glade is or how I can use the grid in gtk2hs.

My glade version: 3.18.2
My gtk2hs version: 0.12.5.7

Kritzefitz
  • 2,644
  • 1
  • 20
  • 35
  • You'll need a TreeView and a TreeModel. – Alfonso Villén Jun 01 '14 at 06:14
  • So, for making a table I need to use a `TreeView`? Is the Original Table in `Graphics.UI.Gtk.Layout.Table` just a wrapper around a `TreeView`? – Kritzefitz Jun 02 '14 at 12:27
  • A table is only for containing and laying out widgets (i.e. buttons, text fields, tree views...), similarly to what vertical and horizontal boxes do. – Alfonso Villén Jun 04 '14 at 21:52
  • That means, that for tables, containing dynamic data, a TreeView is better? – Kritzefitz Jun 05 '14 at 09:52
  • Not that it's better, it's the only option. You store your data in a TreeModel, typically a ListStore or a TreeStore, and use a TreeView to show the data as rows with columns (from a ListStore) or as a tree (TreeStore). If you modify the data in the TreeModel, the TreeView updates itself accordingly. Through the TreeView you can react to user interaction (mouse clicks, cell and/or node edition etc.). In GTK, tables are a way of arranging widgets on a window. There are also boxes, notebooks etc. They can't be used to display data. – Alfonso Villén Jun 06 '14 at 06:12
  • There is a way of using the table for data. You "just" need to manually delete all the labels you put in the table and place new in it and then updater them with `widgetSHowAll`. But I agree that is not a real solution but more like a hack. – Kritzefitz Jun 06 '14 at 06:42
  • You could write your suggestion as an answer. It was very helpful. – Kritzefitz Jun 06 '14 at 08:58
  • Thank you. I'll expand my last comment and write the result as an answer. – Alfonso Villén Jun 06 '14 at 13:16

1 Answers1

4

In GTK, tables are a way of arranging widgets on a window. There are also boxes, notebooks etc. They can't be used to display data.

For showing data, you need a TreeView and a TreeModel.

You store your data in a TreeModel, typically a ListStore or a TreeStore, and use a TreeView to show the data as rows with columns (from a ListStore) or as a tree (TreeStore).

If you modify the data in the TreeModel, the TreeView updates itself accordingly.

Moreover:

  • Several TreeViews can share a TreeModel, and they can display different data columns, or the same data columns in different formats.
  • TreeViews can filter data rows automatically (using TreeModelFilter).
  • They can also sort data rows automatically (using TreeModelSort).
  • And they support drag & drop.

Finally, through the TreeView you can react to user interaction (mouse clicks, cell and/or node edition etc.).

Alfonso Villén
  • 373
  • 1
  • 9