如何在GtkGrid中留空行
我想创建一个带有示例的gtkgrid按钮:
0 1 2 3
------------------------------------------
0 | | button2 |
- button1 -------------------------------
1 | | button3 |
-----------------------------------------
2 | | button4 |
-----------------------------------------
3 | | | | |
-----------------------------------------
4 | | button5 | |
-----------------------------------------
如何在网格中插入一个空行(3),并将该行显示为gui中的空格?
谢谢。
最佳答案
我试图完成类似的任务,但找到了解决方法。我正在使用GTK + 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);
这将产生如下布局:
关于c - 在GtkGrid c中插入空行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11665369/