alsjinus alsjinus - 1 year ago 85
C Question

GTK: Set the size of a grid in C

I want to put a grid inside a fullscreen window.
Labels, entrybars and the button are the widgets attached in the grid. I want to limit the size of grid into something like 350, 200, and place it at the center of the screen. I tried to use height-request and width-request, but they are not working.
Builder.ui looks like this:

<object id="grid" class="GtkGrid">
<property name="visible">True</property>
<property name="row-spacing">30</property>
<property name="column-spacing">20</property>
<property name="column-homogeneous">True</property>
<property name="width-request">350</property>
<property name="height-request">200</property>

But currently my window looks like this:
enter image description here
Can someone please help?

Answer Source

I assume the grid is the immediate child of the window. In your case, changing the size of the grid is not what you want. Instead, you want to change the alignment of the grid in its parent from GTK_ALIGN_FILL to GTK_ALIGN_CENTER in both the horizontal and vertical directions.

In Glade, you can do this near the bottom of the Common tab for the grid.

If this does not work, try putting the grid in another container, such as a GtkBox, and then make that the child of the window, and then make the grid's hexpand and vexpand both TRUE (in the same place in Glade).