How to set and keep the minimum width?

I use some wx.ListCtrl classes in wx.LC_REPORT mode, complemented by ListCtrlAutoWidthMixin.

The problem is this: when the user double-clicks on the column separator (to automatically resize the column), the column width is set according to the width of the content. This is done by the wx library and resizes the column by a few pixels when the control is empty.

I tried to call

self.SetColumnWidth (colNumber, wx.LIST_AUTOSIZE_USEHEADER)

when creating a list, but it just sets the initial column width, not the minimum allowable width.

Has anyone succeeded in setting a minimum column width?

EDIT: Tried to catch

  wx.EVT_LEFT_DCLICK 

without success. This event is not raised when the user double-clicks the column separator. Also tried using

  wx.EVT_LIST_COL_END_DRAG 

this event is usually generated twice for a double click, but I don’t see how I can get information about the new size or how to distinguish a double click from drag & drop. Does anyone have any other ideas?

+4
source share
2 answers

Well, after some struggle, I got a workaround for this. It's ugly in terms of design, but good enough for me.

How it works:

  • Keep the initial column width.

    self.SetColumnWidth(colNum, wx.LIST_AUTOSIZE_USEHEADER) self.__columnWidth[colNum] = self.GetColumnWidth(c) 
  • Register handler for UI update event.

     wx.EVT_UPDATE_UI(self, self.GetId(), self.onUpdateUI) 
  • And write a handler function.

     def onUpdateUI(self, evt): for colNum in xrange(0, self.GetColumnCount()-1): if self.GetColumnWidth(colNum) < self.__columnWidth[colNum]: self.SetColumnWidth(colNum, self.__columnWidth[colNum]) evt.Skip() 

Self.GetColumnCount () - 1 is intentional, so the last column does not change. I know that this is not an elegant solution, but it works well enough for me - you cannot make the columns too small by double-clicking on the delimiters (in fact - you cannot do this at all) and double-clicking on the delimiter after the last column changes the size of the last column to fit the width of the list control.

However, if someone knows the best solution, submit it.

+1
source

Honestly, I stopped using my own wx.ListCtrl in favor of using ObjectListView . There is a little learning curve, but there are many examples. This question will be of interest to your question.

+3
source

All Articles