Is it possible to associate icons of variable width to items in a DataView*Ctrl? (In an IconTextColumn, not using a separate BitmapColumn).
This is as close as I’ve managed to get in a DataViewTreeCtrl:
···
###########################################################
import wx
import wx.dataview as dv
class Tree(dv.DataViewTreeCtrl):
def init(self, parent):
super(Tree, self).init(parent)
self.rootitem = dv.DataViewItem()
self.test1 = self.AppendItem(self.rootitem, 'Test1')
self.test2 = self.AppendItem(self.rootitem, 'Test2')
self.SetItemIcon(self.test1, make_icon(32, wx.RED_BRUSH))
self.SetItemIcon(self.test2, make_icon(16, wx.BLUE_BRUSH))
def make_icon(width, brush):
bitmap = wx.EmptyBitmap(width, 16)
dc.SelectObject(bitmap)
dc.SetBackground(brush)
dc.Clear()
return wx.IconFromBitmap(bitmap)
app = wx.App()
frame = wx.Frame(None)
dc = wx.MemoryDC()
tree = Tree(frame)
dc.SelectObject(wx.NullBitmap)
frame.Centre()
frame.Show()
app.MainLoop()
###########################################################
However the problems with this example are:
- All the “gaps” for the icons take the width of the first-associated icon (try to swap the icon width in the two SetItemIcon calls).
- All the icons are center-aligned in their “gaps”.
- Clicking on an item label for editing, and then confirming the change (e.g. pressing Enter), resets the icon to the last-associated icon.
My expected result would be something like:
- ICON Label
- ICONNNN Label
- ICO Label
- ICONN Label
- IC Label
Where ICON etc. represent variable-width icons; all icons and labels are left-aligned, there’s no gap to the left of the icon and always the same (minimal) gap between icon and label.
My system:
Arch Linux x86_64
GTK+ 2.24.22
wxGTK 3.0.0
wxPython 3.0.0.0