I would like to add a tooltip that shows different text for each item in a wxListCtrl/wxTreeCtrl/wxCheckBox. So far, I haven't been able to find any documentation on how to do this.
You can track mouse positions, use HitTest to find out the item, and then show a wxTipWindow.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
There is a problem with this solution, you need to click or lose focus to
dismiss the tip window. If you want to select an item after the tip window
is shown, you have to click twice (one time to dismiss the tip window, one
time to select the item) which is inelegant. How can I dismiss the tip
window AND select the item with a single click?
Instead of creating a new wxTipWindow, you can call the "SetTip" function of
control's wxToolTip object. Example:
def _OnListCtrlMouseMotion(self,event):
"""This function gets called when the user has moved the mouse above the list-control.
We want to display the tooltip of the item the mousepointer is above.
"""
tooltipObject = self._listctrl.GetToolTip()
newToolTipText = ""
itemnr,hitflags = self._listctrl.HitTest(event.GetPosition())
if itemnr != wx.NOT_FOUND:
itemtext = self._listctrl.GetItemText(itemnr)
newToolTipText = self._itemtext2tooltip[itemtext] or ""