Phil Mayes wrote:
Hi all:
On Windows XP, Python 2.3.5, wxPython 2.6.3.3, the width of tooltip windows is set once for every tooltip window on a dialog, which makes it harder to write visually appealing tips for each control. See small sample below: remove the \n and note that the layout of the second tooltip changes.It seems this is because
a) one window is created for all tooltips:
static WXHWND ms_hwndTT;
b) the max width is set at window creation in wxToolTip::Add(WXHWND hWnd):
SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH, ...The algorithm actually seems to be that the maximum width is based on the shortest width of all the first lines. (Change "this will" to "this\nwill" to see this.) I can't see where in the code this is occurring.
I think it will actually be using the width of the first line of the last tooltip specified that has a '\n' in it. I'll take a look at implementing a fix, (and also looking at more than just the first line, that's just silly.)
Is there some work-around that I am not seeing?
Set the tooltip with the longest first line last. For example:
import wx
class Dlg(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None)
a = wx.TextCtrl(self, -1)
b = wx.TextCtrl(self, -1)
c = wx.TextCtrl(self, -1)
a.SetToolTip(wx.ToolTip("Remove the newline:\n and the next tooltip will change shape"))
b.SetToolTip(wx.ToolTip("this\nhas\nintentional\nshort\nlines"))
c.SetToolTip(wx.ToolTip("this has a longer first line up to here -->\nand also a 2nd line"))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(a)
sizer.Add(b)
sizer.Add(c)
self.SetSizer(sizer)
sizer.Fit(self)
app = wx.PySimpleApp()
dlg = Dlg()
dlg.ShowModal()
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!