I know, that the statusbar displays a tooltip, if the text is too long.
Is it possible to set a tooltip independently explaining the meaning of the information displayed? This would help a new user to grasp the information.
I know, that the statusbar displays a tooltip, if the text is too long.
Is it possible to set a tooltip independently explaining the meaning of the information displayed? This would help a new user to grasp the information.
It appears that the statusbar tooltip string can be set independently of the string displayed if it is too long.
The test code:
def update_tooltip(evt):
text = self.StatusBar.StatusText
if text:
self.StatusBar.ToolTip = f"{text!r} means that ..."
self.StatusBar.Bind(wx.EVT_ENTER_WINDOW, update_tooltip)
Thanks. I get the following error:
wx._core.wxAssertionError: C++ assertion "!HasFlag(0x0020)" failed at /home/wxpy/wxPython-4.2.0/ext/wxWidgets/include/wx/statusbr.h(200) in DoSetToolTip(): Do not set tooltip(s) manually when using wxSTB_SHOW_TIPS!
which somehow makes sense, since I want to have a tooltip displayed, when the string is too long.
What I am looking for is a way to set a tooltip individually for fields, but not the very first. (Sorry, I forgot to mention it in my original post.)
Yes, I just ignored the error. As it said, setting self.StatusBar.WindowStyle ^= wx.STB_SHOW_TIPS
seems OK.
One possible way would be to check the field index every time:
def update_tooltip(evt):
for i in range(self.StatusBar.FieldsCount):
x, y, w, h = self.StatusBar.GetFieldRect(i)
if evt.x < x+w:
break
text = self.StatusBar.GetStatusText(i)
if text:
self.StatusBar.ToolTip = f"{text!r} means that ..."
Also, it’s better to bind to EVT_MOTION
instead of EVT_ENTER_WINDOW
.
I see. Thanks.
How would I make the tooltip appear nearer to the field?
If you bind EVT_MOTION
to the statusbar, the handler will pop up a tooltip at the mouse position while moving inside the statusbar.
But if you want to display tooltips at a fixed point in each field, it is better to use wx.PopupWindow
or wx.PopupTransientWindow
instead of wx.ToolTip
.