TextCtrl seems to align to top on Win 7

The textctrl shown in the attached screenshot was created as a child of a wx.Panel simply with self.edit = wx.TextCtrl(self).

On Linux (not shown), it works fine, but on Windows 7 the text seems to be aligned to the top. Is there a solution for this?

textctrl.png

Mark wrote:

The textctrl shown in the attached screenshot was created as a child of a wx.Panel simply with self.edit = wx.TextCtrl(self).
On Linux (not shown), it works fine, but on Windows 7 the text seems to be aligned to the top. Is there a solution for this?

How do you define "works fine"? If you don't want top-aligned, what do you want?

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Please create a small runnable sample that demonstrates the problem.

···

On Friday, April 19, 2019 at 2:29:27 AM UTC-7, Mark wrote:

The textctrl shown in the attached screenshot was created as a child of a wx.Panel simply with self.edit = wx.TextCtrl(self).

On Linux (not shown), it works fine, but on Windows 7 the text seems to be aligned to the top. Is there a solution for this?

Robin

I’ve attached edit.py (22 LOC) + Windows 7 + Ubuntu 18 screenshots that show the issue.

edit.py (882 Bytes)

lin.png

win.png

This happens because you specified wx.EXPAND. On your Windows system, the button is taller than the default text box, so the button dictates the height of the sizer, and the textbook expands to fill that space. If you remove wx.EXPAND, then the wx.ALIGN_CENTRE_VERTICAL would let the text box be its natural height, with its center aligned with the button's center.

···

On Apr 19, 2019, at 11:44 PM, Mark <list@qtrac.plus.com> wrote:

I've attached edit.py (22 LOC) + Windows 7 + Ubuntu 18 screenshots that show the issue.


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

You’re right — but that means that the textctrl doesn’t grow to fill the horizontal space. So what I really need is expand horizontally but not vertically — is this possible?

Thanks.

···

On Saturday, 20 April 2019 08:08:24 UTC+1, Tim Roberts wrote:

On Apr 19, 2019, at 11:44 PM, Mark li...@qtrac.plus.com wrote:

I’ve attached edit.py (22 LOC) + Windows 7 + Ubuntu 18 screenshots that show the issue.

This happens because you specified wx.EXPAND. On your Windows system, the button is taller than the default text box, so the button dictates the height of the sizer, and the textbook expands to fill that space. If you remove wx.EXPAND, then the wx.ALIGN_CENTRE_VERTICAL would let the text box be its natural height, with its center aligned with the button’s center.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Put the textctrl in a horizontal box sizer with proportion=1, so it will grow to all horizontal space given to the sizer, and with ALIGN_CENTER_VERTICAL. Then add the box sizer to the grid sizer with wx.EXPAND but without any other flags or borders. This way, the grid sizer will give all space available for that cell to the box sizer, and the box sizer can then align the control within that space how you want it.

···

On Saturday, April 20, 2019 at 12:19:02 AM UTC-7, Mark wrote:

You’re right — but that means that the textctrl doesn’t grow to fill the horizontal space. So what I really need is expand horizontally but not vertically — is this possible?

Robin

This is a very common misunderstanding. wx.EXPAND only affects one direction. In a horizontal sizer, wx.EXPAND says that this item should expand vertically to fill the row. In a vertical sizer, wx.EXPAND says that this item should expand horizontally to fill the column.

As Robin suggests, stretching the same direction as the sizer is controlled by the proportion parameter.

···

On Apr 20, 2019, at 12:19 AM, Mark <list@qtrac.plus.com> wrote:

You're right --- but that means that the textctrl doesn't grow to fill the horizontal space. So what I really need is expand horizontally but not vertically --- is this possible?


Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

In a grid sizer it expands the item both ways. I’ve often wished for a horizontal-only and vertical-only EXPAND flag, but embedding a box sizer works well and is not too difficult.

···

On Saturday, April 20, 2019 at 11:57:07 AM UTC-7, Tim Roberts wrote:

On Apr 20, 2019, at 12:19 AM, Mark list@qtrac.plus.com wrote:

You’re right — but that means that the textctrl doesn’t grow to fill the horizontal space. So what I really need is expand horizontally but not vertically — is this possible?

This is a very common misunderstanding. wx.EXPAND only affects one direction. In a horizontal sizer, wx.EXPAND says that this item should expand vertically to fill the row. In a vertical sizer, wx.EXPAND says that this item should expand horizontally to fill the column.

Robin

That works perfectly, thank you. (I’ve attached updated edit.py for completeness.)

edit.py (963 Bytes)

···

On Saturday, 20 April 2019 19:49:14 UTC+1, Robin Dunn wrote:

On Saturday, April 20, 2019 at 12:19:02 AM UTC-7, Mark wrote:

You’re right — but that means that the textctrl doesn’t grow to fill the horizontal space. So what I really need is expand horizontally but not vertically — is this possible?

Put the textctrl in a horizontal box sizer with proportion=1, so it will grow to all horizontal space given to the sizer, and with ALIGN_CENTER_VERTICAL. Then add the box sizer to the grid sizer with wx.EXPAND but without any other flags or borders. This way, the grid sizer will give all space available for that cell to the box sizer, and the box sizer can then align the control within that space how you want it.

Robin