static box sizing problems

Robert Anderson rwa000 at gmail.com
Fri Dec 28 11:20:41 PST 2007


I am using wxWidgets 2.8.7 on a linux box using the GTK build.

I have pared down my issue to the simplest case:  I am trying to use a
horizontal BoxSizer to split a frame into two sections:  a left and right
side.  I want the left side to stretch proportionally and I want the right
side to be of a fixed width.  Moreover, I want to enclose the right side in
a wxStaticBox.

I happen to be using wxRuby, but the code should be understandable to C++
programmers.  This is in the constructor of my frame subclass:

    lr_sizer =3D BoxSizer.new( HORIZONTAL )

    txt =3D StaticText.new(self, -1, "Text Left")
    lr_sizer.add(txt, 1, EXPAND | ALL, 4)

    static_box =3D StaticBox.new(self, -1, "Static Box")
    right_sizer =3D StaticBoxSizer.new( static_box, VERTICAL )

    lr_sizer.add(right_sizer, 0, EXPAND | ALL, 4)
    set_sizer(lr_sizer)
    layout()


This code runs and gives almost what I want.  The text appears on the left
and the static box on the right.  However, the static box is a tiny sliver.
What I want is to fix the width of the static box.  So I try adding a size
argument to the static box constructor:

   static_box =3D StaticBox.new(self, -1, "Static Box", :size =3D> [100, 40=
] )


But now I get something very unexpected to me.  The static box is indeed
wider, but it has the same left hand screen coordinate as it did when it was
a sliver, so that the static box is mostly out of the frame.  I only see a
tiny slice of it.  Resizing the frame moves the whole box, so it is always
most out of the frame.  It is as if the static box were positioned according
to the minimum size, and then grown to the right, to respect the requested
box size.  But this is clearly not what I want.  I want the box to be sized
as requested, and then fit using the spacers.

How do I do that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20071228/8ee=
50c37/attachment.htm


More information about the wx-users mailing list