Activating wx.LC_NO_HEADER -> lots of empty white space being added to the ListCtrl

Hi, I want to remove my header from my ListCtrl. This should be a walk in the park, but even though the header disappears, two columns worth of blank space is added to the right of my list.
Why? How can I avoid this?
Best regards, Odin.

With header:

WithHeader.PNG
WithoutHeader.PNG

Without header:


import wx

import wx.grid

CCODEs = [‘CARC’,‘THER’,‘ZETA’,‘TENS’]

class Mat1(wx.Frame):

def __init__(self, parent):
    wx.Frame.__init__(self, parent)
    self.SetTitle('InputFileGenerator')
    self.Maximize(True)

    #Title
    font = self.GetFont()
    font.SetPointSize(20)
    title = wx.StaticText(self,-1,'  Material')
    title.SetFont(font)

    # Conf button
    confButton = wx.Button(self, -1, "Confirm")
    confButton.Bind(wx.EVT_BUTTON, self.OnConf)

    # KeyDown
    self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

    #DragSource
    self.source = wx.ListCtrl(self, style=wx.LC_LIST | wx.LC_SORT_ASCENDING | wx.LC_SINGLE_SEL)
    self.source.SetColumnWidth(0,60)
    for code in CCODEs:
        self.source.InsertItem(0,code)

    self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.OnDragInit, id=self.source.GetId())
    self.source.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)

    #DropTarget
    self.target = wx.ListCtrl(self, style=wx.LC_REPORT
                                          #| wx.LC_NO_HEADER #<--------------------------------------------------------------------------------------------------
                                          > wx.LC_VRULES
                                          > wx.LC_HRULES
                              )
    self.target.InsertColumn(1, 'No.')
    self.target.InsertColumn(2, 'Type')
    self.target.SetColumnWidth(0, 40)
    self.target.SetColumnWidth(1, 60)
    self.target.SetColumnWidth(2, 0)
    self.target.InsertItem(0, 'No.')
    self.target.SetItem(0, 1, 'Type')
    f = self.target.GetItemFont(0)
    f.SetWeight(wx.FONTWEIGHT_BOLD)
    self.target.SetItemFont(0,f)

    self.target.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
    dt = MyTextDropTarget(self.target)
    self.target.SetDropTarget(dt)

    vbox = wx.BoxSizer(wx.VERTICAL)
    vbox2 = wx.BoxSizer(wx.VERTICAL)
    hbox = wx.BoxSizer(wx.HORIZONTAL)
    vbox2.AddStretchSpacer(12)
    vbox2.Add(self.source, 10, 0, 0)
    vbox2.AddStretchSpacer(12)
    hbox.AddStretchSpacer(10)
    hbox.Add(vbox2, 1, wx.EXPAND, 0)
    hbox.AddStretchSpacer(5)
    hbox.Add(self.target, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 0)
    hbox.AddStretchSpacer(10)
    vbox.AddStretchSpacer(1)
    vbox.Add(title, 0, 0, 20)
    vbox.AddStretchSpacer(5)
    vbox.Add(hbox, 10, wx.ALIGN_CENTER,0)
    vbox.AddStretchSpacer(10)
    vbox.Add(confButton, 0, wx.ALIGN_RIGHT, 0)
    vbox.SetSizeHints(self)
    self.SetSizer(vbox)

def OnDragInit(self, event):

    text = self.source.GetItemText(event.GetIndex())
    tdo = wx.TextDataObject(text)
    tds = wx.DropSource(self.source)

    tds.SetData(tdo)
    tds.DoDragDrop(True)

def OnKeyDown(self, e):
    keycode = e.GetKeyCode()
    if keycode == wx.WXK_DELETE or keycode == wx.WXK_BACK:
        self.target.DeleteItem(self.target.GetItemCount()-1)
    elif keycode == wx.WXK_RETURN:
        self.OnConf()
    else:
        e.Skip()

def OnConf(self,e):
    self.Destroy()

class MyTextDropTarget(wx.TextDropTarget):

def __init__(self, object):
    wx.TextDropTarget.__init__(self)
    self.object = object

def OnDropText(self, x, y, data):
    index = self.object.GetItemCount()
    self.object.InsertItem(index,str(index))
    self.object.SetItem(index, 1, data)
    return True

def main():
app = wx.App()
frame = Mat1(None)
frame.Show()
app.MainLoop()

if name == ‘main’:
app = wx.App()
main()


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

--

You received this message because you are subscribed to the Google Groups "wxPython-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit [https://groups.google.com/d/msgid/wxpython-users/fe08817a-d32a-45e6-b720-cf7a77c62a4d%40googlegroups.com](https://groups.google.com/d/msgid/wxpython-users/fe08817a-d32a-45e6-b720-cf7a77c62a4d%40googlegroups.com?utm_medium=email&utm_source=footer).

</details>

It looks like the listctrl calculates its best size using the column widths only if there are column headers (and columns):

https://github.com/wxWidgets/wxWidgets/blob/master/src/common/listctrlcmn.cpp#L183

You can override the self-calculated best size by setting the min size. The sizers will use that over the best size if it’s set.

···

Robin

Discuss wxPython

On Thursday, July 25, 2019 at 8:20:24 AM UTC-7, Sommerforsker wrote:

Hi, I want to remove my header from my ListCtrl. This should be a walk in the park, but even though the header disappears, two columns worth of blank space is added to the right of my list.
Why? How can I avoid this?

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/2e0752b4-3290-438b-8c66-37c71929ecb8%40googlegroups.com.

That solved it!

Thanks a lot.

Best regards, Odin.

fredag 26. juli 2019 05.39.02 UTC+2 skrev Robin Dunn følgende:

···

It looks like the listctrl calculates its best size using the column widths only if there are column headers (and columns):

https://github.com/wxWidgets/wxWidgets/blob/master/src/common/listctrlcmn.cpp#L183

You can override the self-calculated best size by setting the min size. The sizers will use that over the best size if it’s set.

Robin

Discuss wxPython

On Thursday, July 25, 2019 at 8:20:24 AM UTC-7, Sommerforsker wrote:

Hi, I want to remove my header from my ListCtrl. This should be a walk in the park, but even though the header disappears, two columns worth of blank space is added to the right of my list.
Why? How can I avoid this?

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/521e7c99-36e8-4288-8e93-55928e5c734a%40googlegroups.com.