Adding ListCtrl subclass causes original widget size to "hoover" over the new

Hello,

I've got a fairly strange problem which I'm unable to solve so far.

I've created a VirtualListCtrl class which subclasses ListCtrl, but when Im
adding the VirutalListCtrl to a panel - even if I put it inside a sizer - a
duplicate widget with the "original" size of the widget will be visible over
(or sometimes under) the resized version.

As soon as I resize the window, this duplicate disappears.

This is my VirtualListCtrl code:

listctrlbug.png

···

---
class VirtualListCtrl(wx.ListCtrl):

    def __init__(self, parent):
        wx.ListCtrl.__init__(self, parent, -1,
                             style=wx.LC_REPORT|
                             wx.LC_VIRTUAL|
                             wx.LC_HRULES|
                             wx.LC_VRULES|
                             wx.SUNKEN_BORDER)
        self.parent = parent

        self.InsertColumn(0, 'Timestamp')
        self.InsertColumn(1, 'Name')
        self.InsertColumn(2, 'Level')
        self.InsertColumn(3, 'Message')

        self.SetColumnWidth(0, 200)
        self.SetColumnWidth(1, 100)
        self.SetColumnWidth(2, 100)
        self.SetColumnWidth(3, 400)
---

I am adding the ListCtrl to my panel using:

self.listCtrl = VirtualListCtrl(self.panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.listCtrl, 1, wx.EXPAND|wx.GROW)
self.panel.SetSizer(sizer)
self.panel.SetAutoLayout(True)

Attached is a screencapture of the effect Im seeing. As soon as I resize the
window, the "duplicate" widget will disappear and everything is normal.

I've tried every Refresh() and Update() I can think of, and nothing seems to
fix this issue.

Thanks for any suggestion.

Best regards,
Frank

Frank Aune wrote:

Attached is a screencapture of the effect Im seeing. As soon as I resize the window, the "duplicate" widget will disappear and everything is normal.

One possibility is that there is not a size event happening after these widgets are created, and so they are left at their default size. The default size event handler is where the auto-layout is done. One case where this can happen is if you create your frame with a specific size and/or it is shown before the widgets are created. To work around this you can try sending an extra size event yourself with frame.SendSizeEvent().

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!