如何将小部件置于网格-GTK C中
我正在尝试将这些按钮集中在此网格中,但是我尝试了SET_HEXPAND和变体,而没有什么是我想要的。
GtkWidget *p_main_grid = gtk_grid_new();
gtk_grid_set_column_spacing(GTK_GRID(p_main_grid), 16);
gtk_grid_set_row_spacing(GTK_GRID(p_main_grid), 16);
/* Buttons */
GtkWidget *p_button_1 = gtk_button_new_with_label("Button 1");
GtkWidget *p_button_2 = gtk_button_new_with_label("Button 2");
/* Add Buttons to grid */
gtk_grid_attach(GTK_GRID(p_main_grid), p_button_1, 5, 3, 1, 1);
gtk_grid_attach_next_to(GTK_GRID(p_main_grid), p_button_2, p_button_1,
GTK_POS_RIGHT, 1, 1);
/* Add grid to main window */
gtk_window_set_child(GTK_WINDOW(p_main_window), p_main_grid);
gtk_window_present(GTK_WINDOW(p_main_window));
我在linux上,使用gtk4
I'm trying to center these buttons in a this grid but I've tried set_hexpand and variants and nothing's what I'm looking for.
GtkWidget *p_main_grid = gtk_grid_new();
gtk_grid_set_column_spacing(GTK_GRID(p_main_grid), 16);
gtk_grid_set_row_spacing(GTK_GRID(p_main_grid), 16);
/* Buttons */
GtkWidget *p_button_1 = gtk_button_new_with_label("Button 1");
GtkWidget *p_button_2 = gtk_button_new_with_label("Button 2");
/* Add Buttons to grid */
gtk_grid_attach(GTK_GRID(p_main_grid), p_button_1, 5, 3, 1, 1);
gtk_grid_attach_next_to(GTK_GRID(p_main_grid), p_button_2, p_button_1,
GTK_POS_RIGHT, 1, 1);
/* Add grid to main window */
gtk_window_set_child(GTK_WINDOW(p_main_window), p_main_grid);
gtk_window_present(GTK_WINDOW(p_main_window));
I'm on linux and using gtk4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在gtk3中使用了它,并以两个按钮为中心。
这试图使用10列和10行。
16的间距似乎在按钮之间提供了一定的距离。
这与4乘3行一起工作
I used this in gtk3 and it centered two buttons.
This tries to use 10 columns and 10 rows.
The spacing of 16 seems to provide some distance between the buttons.
This is working with 4 cols by 3 rows