Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert empty row in GtkGrid c

Tags:

c

gtk

How to leave a empty row in GtkGrid

I want to create a gtkgrid with buttons like in example:

        0         1        2         3
   ------------------------------------------
0  |         |           button2           |      
   - button1 -------------------------------
1  |         |           button3           |
   -----------------------------------------
2  |         |           button4           |
   -----------------------------------------
3  |         |         |         |         |
   -----------------------------------------
4  |         |      button5      |         |
   -----------------------------------------

How to insert a empty row (3) in grid and this row to show as space in gui?

Thanks.

like image 203
Cecylia Avatar asked Jul 26 '12 08:07

Cecylia


1 Answers

I was trying to accomplish a similar task and found a work-around. I'm using GTK+3. I just added an empty label to one of the cells in the 3rd row to cause GTK to allocate space for the row without displaying anything.

You could do something like this (I'm assuming the second button2 was meant to be button5):

// Declare widgets.
    GtkWidget *button1 = gtk_button_new_with_label("button1");
    GtkWidget *button2 = gtk_button_new_with_label("button2");
    GtkWidget *button3 = gtk_button_new_with_label("button3");
    GtkWidget *button4 = gtk_button_new_with_label("button4");
    GtkWidget *button5 = gtk_button_new_with_label("button5");
    GtkWidget *space = gtk_label_new("");
    GtkWidget *buttonGrid = gtk_grid_new();

//  Attach to the grid.
    gtk_grid_attach(GTK_GRID(buttonGrid),button1,0,0,1,2);
    gtk_grid_attach(GTK_GRID(buttonGrid),button2,1,0,3,1);
    gtk_grid_attach(GTK_GRID(buttonGrid),button3,1,1,3,1);
    gtk_grid_attach(GTK_GRID(buttonGrid),button4,1,2,3,1);
    gtk_grid_attach(GTK_GRID(buttonGrid),button5,1,4,2,1);
    gtk_grid_attach(GTK_GRID(buttonGrid),space,2,3,1,1);
    gtk_grid_set_column_homogeneous(GTK_GRID(buttonGrid),TRUE); 

This produces a layout like this: layout produced

like image 115
rmfield Avatar answered Nov 06 '22 14:11

rmfield