Grid Creation in GTK +

I am not asking for code implementation, but given the GTK + skill set, from an abstract point of view, is there a better way to implement the grid in such a way that every square is clickable and the like?

+4
source share
3 answers

Personally, for this I would use a table - http://library.gnome.org/devel/gtk/stable/GtkTable.html - and fill it with buttons - http://library.gnome.org/devel/gtk/stable/GtkButton .html From there, if you don't want the buttons to look like they were buttons, I would set the relief - http://library.gnome.org/devel/gtk/stable/GtkButton.html#gtk-button-set-relief - None.

Performing this method will give you a grid, where each element is the same size, and the event is fired when an element is clicked in the grid.

The above assumes that the grid will have more than one row, if you plan to have only one row, you would be better off using either GtkHButtonBox - http://library.gnome.org/devel/gtk/stable/GtkHButtonBox.html - or GtkVButtonBox - http://library.gnome.org/devel/gtk/stable/GtkVButtonBox.html .

+5
source

If the grid is large, you can also consider GtkTreeView .

It can display trees as grids and supports rectangular selection. Cells can display text, numbers, and simple widgets such as buttons, radio buttons, options menus, progress bars, etc. It works well even on large data sets (many thousands of rows) and has nice features like sorting columns, etc.

The API is quite complex, however :-( This is the complete MVC thing and makes you think a little that it works well.

Here is a sample code in gtk-demo: see a demo of "Editable Cells" in the "Tree View" section.

+5
source

In the second attempt to use GtkTable for basic grid organization, it is very easy to get a grid view. You can also examine the filling of each cell with a simple GtkEventBox , if you do not need a built-in button picture.

Eventbox is an invisible widget that basically adds a window and makes a closed area accessible. It is useful to make some of the โ€œquieterโ€ GTK + widgets more interactive, for example, commonly used for GtkLabel to make it interactive; if the label provides sufficient drawing ability for your needs, this is a possible way to continue.

0
source

All Articles