atom feed5 messages in com.googlegroups.wxpython-usersHow to handle word-wrapping static text?
FromSent OnAttachments
Erik WestraDec 22, 2004 10:59 am 
Nigel RoweDec 22, 2004 2:14 pm 
Erik WestraDec 22, 2004 4:14 pm 
Robin DunnDec 23, 2004 4:25 pm 
Roger BinnsDec 24, 2004 8:07 am 
Subject:How to handle word-wrapping static text?
From:Erik Westra ("
Date:Dec 22, 2004 10:59:11 am

Greetings of the Season to you all!

I have a question about the "right" way to handle word-wrapping static text within a window. In my application, I have lots of places where I need to include what amounts to a wx.StaticText control within a window, and have its position and size controlled by a wx.Sizer. The string to display can sometimes be short, but other times might consist of up to, say, a hundred words of text, so the text needs to word-wrap nicely to fit within the space allocated to it by the sizer (which, it appears, means that wx.StaticText isn't suitable, as it doesn't appear to word-wrap correctly when running under MS Windows). I also can't use an uneditable wx.TextCtrl, because the height of the control must vary according to how many lines of text it uses. Ideally, the text should adjust the word-wrapping dynamically if the user resizes the frame. And, of course, this needs to work on both the Mac and MS Windows.

I've done some digging through the mailing list archives, and it appears that this isn't easy to do -- but surely it's something that people need quite often. I avoided the problem initially by hard-coding newlines into the text to display, but when I went to port my application from Windows to the Mac the windows all look ugly because the text sizes and character widths are all different. It now looks like I either need a generic solution, or else include separate versions of each string to display, with newlines embedded in different places, for each playform. Urgh!

How have others handled this problem? Is there a generic solution to making sure this works correctly across all platforms? I've had a go at creating my own "WrappingStaticTextCtrl" class based on wx.lib.stattext.GenStaticText, but it's a bit of an ugly hack and doesn't really work all that well. There must be a better way. Any suggestions?


- Erik.