如何防止GtkWindow增长? [英] How to prevent GtkWindow growing?

查看:67
本文介绍了如何防止GtkWindow增长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

#include<gtk/gtk.h>
int main(int argc,char**argv)
{
   GtkWidget* window, *button, *grid;
   gtk_init(&argc,&argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size(GTK_WINDOW(window),100,100);
   g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
   //gtk_container_set_border_width(GTK_CONTAINER(window),10);
   gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

   grid = gtk_grid_new();
   button = gtk_button_new_with_label("1");
   gtk_grid_attach(GTK_GRID(grid), button, 0,0, 100, 1);
   gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
   gtk_grid_set_row_homogeneous(GTK_GRID(grid), TRUE);

   button = gtk_button_new_with_label("1");
   gtk_grid_attach(GTK_GRID(grid), button,0, 1, 10, 1);
   gtk_container_add(GTK_CONTAINER(window), grid);
   gtk_widget_show_all(window);
   gtk_main();
   return 0;
}

此代码的结果是: gtk_grid_attach(GTK_GRID(grid),button,0,1,100,1)

当我将gtk_grid_attach(GTK_GRID(grid),button,0,1,100,1)更改为gtk_grid_attach(GTK_GRID(grid),button,0,1,200,1) 那么此代码的结果是: gtk_grid_attach(GTK_GRID(grid),button,0,1,200,1)

When I change gtk_grid_attach(GTK_GRID(grid), button,0, 1, 100, 1) to gtk_grid_attach(GTK_GRID(grid), button,0, 1, 200, 1) Then the result of this code is: gtk_grid_attach(GTK_GRID(grid), button,0, 1, 200, 1)

为什么窗口的宽度会增加?我发现,窗口的大小可能会随gtk_grid_attach()函数而变化.那么如何解决呢?

Why does the width of window increase? I find that the size of window may be varied with the function gtk_grid_attach(). So how to solve it?

推荐答案

为什么窗口的宽度会增加?

Why does the width of window increase?

您已经使用

   gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
   gtk_grid_set_row_homogeneous(GTK_GRID(grid), TRUE);

这意味着网格中的每个单元格都将具有相等的宽度和高度,这将与嵌入的最大窗口小部件相同.因此,如果您有更多的单元格,网格将进一步扩大,因此窗口宽度会增加

Which means that each cell in the grid will have equal width and height, which will be the same as the largest widget embedded. So If you have more cells, the grid will grow further and thus the window width increases

我发现可以通过函数gtk_grid_attach()来改变窗口的大小.那么如何解决呢?

I find that the size of window may be varied with the function gtk_grid_attach(). So how to solve it?

我不知道您的用例是什么.但是,在附加子级时,您可以取消设置均质属性和/或使用实际的网格宽度和高度.

I don't know what's your usecase is. But you could unset the homogeneous properties and/or use a real grid width and height when attaching children.

这篇关于如何防止GtkWindow增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆