在GtkGrid c中插入空行

时间:2012-07-26 08:32:44

标签: c gtk

如何在GtkGrid中留空行

我想创建一个带有按钮的gtkgrid,例如:

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

如何在网格中插入一个空行(3),并将此行显示为gui中的空格?

感谢。

1 个答案:

答案 0 :(得分:3)

我正在尝试完成类似的任务并找到了解决方法。我正在使用GTK + 3。我刚刚在第3行的一个单元格中添加了一个空标签,以使GTK为行分配空间而不显示任何内容。

你可以这样做(我假设第二个button2应该是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); 

这会产生如下布局: layout produced