GTK4.jl: Canvas not visible when pushed to a box

Hello. I am trying to display a canvas GTK4.jl. The documentation example works.

But when I push the canvas to a GTKBox and push the box to the window (instead of pushing the canvas directly to the window), the canvas is not visible

using Gtk4, Graphics

c = GtkCanvas()
window = GtkWindow("Canvas")

@guarded draw(c) do widget
    ctx = getgc(c)
    h = height(c)
    w = width(c)
    # Paint red rectangle
    rectangle(ctx, 0, 0, w, h/2)
    set_source_rgb(ctx, 1, 0, 0)
    fill(ctx)
    # Paint blue rectangle
    rectangle(ctx, 0, 3h/4, w, h/4)
    set_source_rgb(ctx, 0, 0, 1)
    fill(ctx)
end

#
box = GtkBox(:v) 
push!(box, c)
push!(window,box)

show(window); # trigger rendering

Thanks in advance !

c.hexpand = c.vexpand = true

solves this. Probably this is a bug and the Canvas should expand by default.

1 Like