How to position widgets correctly with the Gtk4 grid

I’m starting to study Gtk4 made available by https://juliagtk.github.io/Gtk4.jl/dev/manual/layout/#GtkGrid
And I managed to run the example:

win = GtkWindow("A new window")
g = GtkGrid()
a = GtkEntry()  # a widget for entering text
a.text = "This is Gtk!"
b = GtkCheckButton("Check me!")
c = GtkScale(:h, 0:10)     # a slider

# Now let's place these graphical elements into the Grid:
g[1,1] = a    # Cartesian coordinates, g[x,y]
g[2,1] = b
g[1:2,2] = c  # spans both columns
g.column_homogeneous = true # grid forces columns to have the same width
g.column_spacing = 15  # introduce a 15-pixel gap between columns
push!(win, g)

However, if you comment on lines 9 and 11 (a and c), GtkCheckButton b appears in position (1,1) instead of the specification (2,1)

win = GtkWindow("A new window")
g = GtkGrid()
a = GtkEntry()  # a widget for entering text
a.text = "This is Gtk!"
b = GtkCheckButton("Check me!")
c = GtkScale(:h, 0:10)     # a slider

# Now let's place these graphical elements into the Grid:
#g[1,1] = a    # Cartesian coordinates, g[x,y]
g[2,1] = b
#g[1:2,2] = c  # spans both columns
g.column_homogeneous = true # grid forces columns to have the same width
g.column_spacing = 15  # introduce a 15-pixel gap between columns
push!(win, g)

Could anyone help me understand the reason for this?

The widget only makes space for a first column if there is a widget occupying it, even when column_homogeneous = true is set. If you add anything to the first column, even an empty layout widget, for example using g[1,1] = GtkBox(:h), it does show the empty first column.

1 Like

Huuum I thought it could be that… I’m kind of learning on my own, so as this information wasn’t included in this part of the documentation, I thought I’d better ask. Thanks for the feedback!