Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

Checkbox of ListCtrl disappears when the tooltip is set manually

Open komoto48g opened this issue 3 years ago • 1 comments

Operating system: Windows 10 wxPython version & source: 4.1.1 (pypi) Python version & source: 3.8.6, 3.9.9

Description of the problem: If you manually set ListCtrl.Tooltip and hover the mouse, the checkbox disappears. This issue occurs in wx4.1.1. There is no problem with 4.0.7. To work around this bug, the Tooltip should be set as a blank string (not None) before EnableCheckBoxes. However, this time the default tooltip for displaying truncated items disappears.

Code Example (click to expand)
import wx

if wx.VERSION < (4,1,0):
    from wx.lib.mixins.listctrl import CheckListCtrlMixin
    
    class CheckList(wx.ListCtrl, CheckListCtrlMixin):
        def __init__(self, *args, **kwargs):
            wx.ListCtrl.__init__(self, *args, **kwargs)
            CheckListCtrlMixin.__init__(self)
            
            ## self.ToolTip = ''
            self.IsItemChecked = self.IsChecked # for wx 4.1 compatibility
else:
    class CheckList(wx.ListCtrl):
        def __init__(self, *args, **kwargs):
            wx.ListCtrl.__init__(self, *args, **kwargs)
            
            ## To avoid $BUG wx 4.1.1 (but default Tooltip will disappear)
            ## self.ToolTip = ''
            self.EnableCheckBoxes()

musicdata = [
    ("Bad English", "The Price Of Love", "Rock"),
    ("DNA featuring Suzanne Vega", "Tom's Diner", "Rock"),
    ("George Michael", "Praying For Time", "Rock"),
    ("Gloria Estefan", "Here We Are", "Rock"),
    ("Linda Ronstadt", "Don't Know Much", "Rock"),
    ("Michael Bolton", "How Am I Supposed To Live Without You", "Blues"),
]

class CheckList(CheckList):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        self.InsertColumn(0, "Artist")
        self.InsertColumn(1, "Title", wx.LIST_FORMAT_RIGHT)
        self.InsertColumn(2, "Genre")
        
        for key, data in enumerate(musicdata):
            index = self.InsertItem(self.GetItemCount(), data[0])
            self.SetItem(index, 1, data[1])
            self.SetItem(index, 2, data[2])
            self.SetItemData(index, key)
            
        self.Bind(wx.EVT_MOTION, self.OnMotion)
        
    def OnMotion(self, evt):
        j, flag = self.HitTest(evt.Position)
        tip = ''
        if j >= 0:
            tip = ', '.join(musicdata[j])
        self.ToolTip = tip
        evt.Skip()

app = wx.App()
frm = wx.Frame(None)
frm.lc = CheckList(frm, style=wx.LC_REPORT|wx.LC_HRULES)
frm.Show()
app.MainLoop()

https://user-images.githubusercontent.com/83063554/150175928-bab1825e-0ef0-47f6-889d-55364b9615f6.mp4

komoto48g avatar Jan 19 '22 16:01 komoto48g

😄 This issue seems to be fixed in wxPython 4.2.0. Should I close this?

komoto48g avatar Aug 21 '22 17:08 komoto48g