Re: Center text vertically in a wxStaticText

2,301 views
Skip to first unread message

Guillaume GOURDIN

unread,
Sep 13, 2007, 4:42:39 AM9/13/07
to wx-u...@lists.wxwidgets.org

>> Well, everything is in the topic. My problem is that I have to expand a
>> wxStaticText in a sizer, and I want the text to be vertically centered.
>
> Use wxALIGN_CENTRE_VERTICAL when adding to sizer.

This doesn't work, because the I use the wxEXPAND. And I have to,
beacause I if don't, the text gets wrapped.


Ondra Holub

unread,
Sep 13, 2007, 6:22:20 AM9/13/07
to wx-u...@lists.wxwidgets.org

In which sizer are you adding your static text?

Sometimes may be helpful to add one more sizer (typically wxBoxSizer)
containing only one widget.

Guillaume GOURDIN

unread,
Sep 13, 2007, 7:03:42 AM9/13/07
to wx-u...@lists.wxwidgets.org

> In which sizer are you adding your static text?

wxFlexFridSizer.

Ondra Holub

unread,
Sep 12, 2007, 4:51:50 PM9/12/07
to wx-u...@lists.wxwidgets.org

On 12 Zá , 19:38, Guillaume GOURDIN <gour...@liw.fr> wrote:
> Well, everything is in the topic. My problem is that I have to expand a
> wxStaticText in a sizer, and I want the text to be vertically centered.
>
> Thank you for your help.

Guillaume GOURDIN

unread,
Sep 12, 2007, 1:38:21 PM9/12/07
to wx-u...@lists.wxwidgets.org

Robin Dunn

unread,
Sep 13, 2007, 5:32:07 PM9/13/07
to wx-u...@lists.wxwidgets.org
Guillaume GOURDIN wrote:
>
> Well, everything is in the topic. My problem is that I have to expand a
> wxStaticText in a sizer, and I want the text to be vertically centered.

You'll probably be better off to use the sizer alignment flags to center
the widget within the space given to it by the sizer instead of
expanding the widget to fill the space and trying to get the native
widget to center it. The former works everywhere, but the latter
depends on a feature that the native widget may or may not implement.


--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!


Robin Dunn

unread,
Sep 13, 2007, 5:36:31 PM9/13/07
to wx-u...@lists.wxwidgets.org

Allow the text item to expand horizontally, but not vertically.

Guillaume GOURDIN

unread,
Sep 14, 2007, 5:21:58 AM9/14/07
to wx-u...@lists.wxwidgets.org

> Allow the text item to expand horizontally, but not vertically.

Is this possible? At least in the 2.6.2, there's only a wxEXPAND flag
available.

Robin Dunn

unread,
Sep 14, 2007, 6:07:10 PM9/14/07
to wx-u...@lists.wxwidgets.org

I'd eventually like to split it into wxEXPAND_VERTICALLY and
wxEXPAND_HORIZONTALLY to make this easier, but it can still be done
currently with a bit more work. You need to put the item in a box sizer
and let it do the horizontal expansion and with an
wx_ALIGN_CENTER_VERTICAL flag. Then put the box sizer in the flex grid
sizer with wxEXPAND. That will make the box sizer fill the cell in both
directions, but the widget will be expanded/centered as directed by the
box sizer.

Reply all
Reply to author
Forward
0 new messages