wxpython - Expandir el control de la lista verticalmente, no horizontalmente
Pregunta
Tengo un ListCtrl que muestra una lista de elementos para que el usuario seleccione. Esto funciona bien, excepto que cuando el ctrl no es lo suficientemente grande como para mostrar todos los elementos, quiero que se expanda hacia abajo con una barra de desplazamiento vertical en lugar de usar una barra de desplazamiento horizontal a medida que se expande hacia la derecha.
La creación de ListCtrl:
self.subjectList = wx.ListCtrl(self, self.ID_SUBJECT, style = wx.LC_LIST | wx.LC_SINGLE_SEL | wx.LC_VRULES)
Los elementos se insertan usando wx.ListItem:
item = wx.ListItem()
item.SetText(subject)
item.SetData(id)
item.SetWidth(200)
self.subjectList.InsertItem(item)
Solución
Utilice el estilo wxLC_REPORT .
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_REPORT | wx.LC_NO_HEADER)
for i in range(5):
self.test.InsertColumn(i, 'Col %d' % (i + 1))
self.test.SetColumnWidth(i, 200)
for i in range(0, 100, 5):
index = self.test.InsertStringItem(self.test.GetItemCount(), "")
for j in range(5):
self.test.SetStringItem(index, j, str(i+j)*30)
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
Otros consejos
Prueba esto:
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_ICON | wx.LC_AUTOARRANGE)
for i in range(100):
self.test.InsertStringItem(self.test.GetItemCount(), str(i))
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow