Setting size of GtkCanvas and other widgets

I’m wanting to make a GUI with several items - I made a GtkBox(:v), and pushed in a GtkBox(:h),
followed by a GtkCanvas(), then another GtkBox(:h). The hBoxes contain buttons, labels, etc.
When I call showall(win) it brings up the two hBoxes Ok, but the canvas is sqeezed down to a thin line.
What I want is for it to fill the space between the hboxes. If I call GtkCanvas(width,height) then that
gives me a useable canvas, but it prevents me from resizing the window to less than that size.
I thought if I could trap the resize events I could use set_gtk_property() to adjust the size but I can’t
figure out what string to use with signal_connect(). That would also be useful to adjust sizes in the
hBoxes.

1 Like

have you expanded the canvas?

set_gtk_property!(mybox,:expand,mycanvas,true)

where mybox is the box and mycanvas is the canvas.

Here is a working example (modified from the docs):

using Gtk
c = @GtkCanvas()
b = GtkBox(:h)
push!(b,c)
set_gtk_property!(b,:expand,c,true)
win = GtkWindow(b, "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
showall(win)

The interesting thing is, that I need showall(win) to actually show the canvas. I am not sure why that but stumbled on this several times.

Thanks, that certainly sorts out the canvas problem.

How can I manually set the size (pixel number) for a button? So that it does not scale to the text but relative to some other number