I'm using a the SizedPanel class from wx.lib.sized_controls on macOS
(Sierra 10.12) and can't seem to get children objects to align
vertically. Am I doing something wrong?Yes, although it's subtle. The code is doing what you asked, but what
you asked is not what you wanted. The StaticText control is the only
thing in the main_pane, so it expands to fill the pane. The control
IS vertically centered, occupying the entire space in the pane. (You
can see that because it is colored white.) The issue is that a static
text control does not have the ability to vertically center its own
text within its window. The control is centered, but the text is not.
What you need are spacers, above and below the static text, to suck up
all the extra space. That's normal and easy when you are using sizers
directly, but it's kind of hidden with wx.lib.sized_controls.
Something like this seems to work:
## Row 2 main_pane = self.main_pane =
wxSC.SizedPanel(pane) main_pane.SetBackgroundColour("white")
spacer = wxSC.SizedPanel(main_pane,-1)
spacer.SetSizerProps(proportion=1)
st = wx.StaticText(main_pane, label="main_pane")
st.SetSizerProps(align='center')
spacer = wxSC.SizedPanel(main_pane,-1)
spacer.SetSizerProps(proportion=1)
Tim Roberts, ti...@probo.com <javascript:>
Thanks Tim. The trick with the spacer does work Note: the white area
is the background of the middle pane, not of the static text object. I
set the background of the ST object and it's a different region. I
changed the widget to a generic button to see if that makes any
difference (just in case there was something weird with static text. I
know native macOS buttons don't expand vertically). I can always get the
generic button to be horizontally centred (with or without spacers, and
using vertical or horizontal sized panels), however I can only get the
generic button t be vertically centred if I use the spacer "trick". Is
this right? Why does horizontal centring work, but not vertical centring
(without spacers)? Is this just a known limitation, quirk or feature or
wxWidgets and/or the native GUI framework (macOS cocoa in this case)? I
think what I'm wanting to do is have a static text widget, that doesn't
expand, but is positioned in the centre of the parent pane (main pane).
As the main pane expands, the static text should get repositioned to the
centre. That's how I think it should work conceptually, but it doesn't
(at least for the vertical alignment). I'm trying to work out whether
it is a bug, or whether I've got my wires crossed (or whether it's just
a limitation/quirk that's never going to change). Thanks, Brendan.