modifying wx.Rect() returned from ListCtrl.GetItemRect(item)

Hi,

I’m having some difficulty modifying the wx.Rect returned from ListCtrl.GetItemRect(n). I’m trying to increase the width of list items in a ListCtrl with the LC_ICON flags via

for n, app in enumerate(collection.get_apps()):
    self.applist.InsertItem(n, app.get_name(), ids[n])

    print(self.applist.GetItemRect(n))

    rect = self.applist.GetItemRect(n)
    print(f"old: {rect.GetWidth()}")
    rect.SetWidth(rect.GetWidth()+50)
    self.RefreshRect(rect)
    print(f"new: {rect.GetWidth()}")
    self.applist.RefreshItem(n)

But this doesn't appear to change the actual wx.Rect associated with the list item. I'd like to make the items large enough so that the ListCtrl doesn't truncate the text. Any advice is appreciated.

It doesn’t work that way. The wxRect returned from GetItemRect is not the actual rectangle object used by the control but rather a copy. In fact, on Windows the native control uses a RECT structure which is translated to a new instance of wxRect to be returned. AFAICT we don’t have any way to change the size of ListCtrl items, but you may be able to do something with UltimateListCtrl in AGW. Perhaps via a custom derived class.

···

On Tuesday, May 22, 2018 at 11:52:49 AM UTC-7, kg*2 wrote:

Hi,

I’m having some difficulty modifying the wx.Rect returned from ListCtrl.GetItemRect(n). I’m trying to increase the width of list items in a ListCtrl with the LC_ICON flags via

for n, app in enumerate(collection.get_apps()):
    self.applist.InsertItem(n, app.get_name(), ids[n])

    print(self.applist.GetItemRect(n))

    rect = self.applist.GetItemRect(n)
    print(f"old: {rect.GetWidth()}")
    rect.SetWidth(rect.GetWidth()+50)
    self.RefreshRect(rect)
    print(f"new: {rect.GetWidth()}")
    self.applist.RefreshItem(n)


But this doesn't appear to change the actual wx.Rect associated with the list item. I'd like to make the items large enough so that the ListCtrl doesn't truncate the text. Any advice is appreciated.

Robin

Ah, makes sense. Back to the drawing board. Thanks for clearing it up

···

On Tuesday, May 22, 2018 at 4:04:56 PM UTC-7, Robin Dunn wrote:

On Tuesday, May 22, 2018 at 11:52:49 AM UTC-7, kg*2 wrote:

Hi,

I’m having some difficulty modifying the wx.Rect returned from ListCtrl.GetItemRect(n). I’m trying to increase the width of list items in a ListCtrl with the LC_ICON flags via

for n, app in enumerate(collection.get_apps()):
    self.applist.InsertItem(n, app.get_name(), ids[n])

    print(self.applist.GetItemRect(n))

    rect = self.applist.GetItemRect(n)
    print(f"old: {rect.GetWidth()}")
    rect.SetWidth(rect.GetWidth()+50)
    self.RefreshRect(rect)
    print(f"new: {rect.GetWidth()}")
    self.applist.RefreshItem(n)


But this doesn't appear to change the actual wx.Rect associated with the list item. I'd like to make the items large enough so that the ListCtrl doesn't truncate the text. Any advice is appreciated.

It doesn’t work that way. The wxRect returned from GetItemRect is not the actual rectangle object used by the control but rather a copy. In fact, on Windows the native control uses a RECT structure which is translated to a new instance of wxRect to be returned. AFAICT we don’t have any way to change the size of ListCtrl items, but you may be able to do something with UltimateListCtrl in AGW. Perhaps via a custom derived class.

Robin